2023年4月6日 星期四

Clang recompile with -fPIE PIC Position Independent Code 2023


Problemm:

/usr/bin/ld: _deps/ev-build/libev.a(ev.c.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIE

clang: error: linker command failed with exit code 1 (use -v to see invocation)

 

Way 1

Solution:

Add

-DCMAKE_POSITION_INDEPENDENT_CODE=ON

So that 

/usr/bin/cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DENABLE_CXX_CLANG_TIDY=TRUE -DENABLE_CODE_COVERAGE=TRUE -DCMAKE_C_COMPILER=/usr/bin/clang-15 -DCMAKE_CXX_COMPILER=/usr/bin/clang++-15 -DCMAKE_POSITION_INDEPENDENT_CODE=ON ..


Reference:

https://stackoverflow.com/questions/38296756/what-is-the-idiomatic-way-in-cmake-to-add-the-fpic-compiler-option





readme.md

sudo docker build . -t gfo/cpp-build
sudo docker rm -f cpp-build
sudo docker run --net=host --cap-add sys_ptrace -d --name cpp-build --memory=12g -v "${PWD}/../../../../:/work" gfo/cpp-build tail -F /dev/null
sudo docker exec -it cpp-build bash
mkdir build
cd build
cmake ../ -GNinja -DCMAKE_C_COMPILER=clang-9 -DCMAKE_CXX_COMPILER=clang++-9
ninja -j12
ninja test



Way 2:

Interpolated

/usr/bin/cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=/usr/bin/clang-15 -DCMAKE_CXX_COMPILER=/usr/bin/clang++-15 -DTEST_REPORTER=junit ..

/usr/bin/cmake --build . --target all
/usr/bin/cmake --build . --target test


Raw:

CMAKE_BUILD_DIR=cmake-build-dir
CMAKE_EXEC=/usr/bin/cmake
CXX_BUILD_SYSTEM=Ninja
CXX_BUILD_TYPE=Debug
CLANG_TIDY_FLAG=
CODE_COVERAGE_FLAG=-DENABLE_CODE_COVERAGE=TRUE
EXTRA_CMAKE_FLAGS=-DCMAKE_C_COMPILER=/usr/bin/clang-15 -DCMAKE_CXX_COMPILER=/usr/bin/clang++-15 -DTEST_REPORTER=junit

$ date -R
$ pwd
/builds/subdir/app
$ env | sort
$ mkdir -p ${CMAKE_BUILD_DIR}
$ cd ${CMAKE_BUILD_DIR}
${CMAKE_EXEC} -G"${CXX_BUILD_SYSTEM}" -DCMAKE_BUILD_TYPE=${CXX_BUILD_TYPE} ${CLANG_TIDY_FLAG} ${CODE_COVERAGE_FLAG} ${EXTRA_CMAKE_FLAGS[@]} ..
${CMAKE_EXEC} --build . --target all

${CMAKE_EXEC} --build ${CMAKE_BUILD_DIR} --target test



CoreDump

docker run --privileged <the docker image ID>

setup

sudo sysctl kernel.core_pattern=/var/crash/core.%c.%d.%p.%t.%s.%E
cat /proc/sys/kernel/core_pattern
/var/crash/%E.%p.%t.%s


test

ctest -R "test_name"


repeat test

until ! ctest -R "test_possible_fail"; do     echo ...;     sleep 1; done

2023年2月2日 星期四

How to Enable the Missing Manual Login Option By Editing the Registry 2023 Windows 11

 How to Restore a Missing "Users Must Enter a User Name and Password" Option in Windows 11 (makeuseof.com)




How to Enable the Missing Manual Login Option By Editing the Registry

Alternatively, you can manually edit the registry to restore the missing login option. However, it’s recommended users try the method above first. If that doesn’t do the trick, edit the registry as follows.

  1. Bring up the Power User menu (you can access it with its special Win + X hotkey).
  2. Select Run from the menu.
  3. Open the Registry Editor by entering its regedit Run command and clicking OK.
  4. Navigate to a HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\PasswordLess\Device key within the Registry Editor.
  5. Select the Device key within the left navigation pane.
  6. Double-click the Device key’s DevicePasswordLessBuildVersion DWORD.
  7. Erase the number in the Value data box. Then input 0 there to replace the deleted value.
  8. Click OK to save the new value.

Finally run netplwiz

2022年12月20日 星期二

Generate Core Dump File C++ on Ubuntu 20.04



setup

cat /proc/sys/kernel/core_pattern
|/usr/share/apport/apport -p%p -s%s -c%c -d%d -P%P -u%u -g%g -- %E
$ ulimit -c
0
$ ulimit -c unlimited
0
$ ulimit -c
unlimited

setup
sudo sysctl kernel.core_pattern=/var/crash/core.%c.%d.%p.%t.%s.%E
cat /proc/sys/kernel/core_pattern
/var/crash/%E.%p.%t.%s

code

touch a.cpp
nano

int main() {
int a = 1/0;
int b = a+1;
return 0;
}

g++ a.cpp
./a.out
Floating point exception (core dumped)

dump

ll /var/crash/
core.18446744073709551615.1.30876.1671522014.8.!home!user!a.out

 

No use

ll /var/lib/apport/coredump
sudo sysctl kernel.core_pattern=core.%p.%s.%c.%d.%P

Reference

https://askubuntu.com/questions/440708/unable-to-generate-core-dump-after-apport-disable

2022年12月16日 星期五

docker with postgres:14.3

https://medium.com/alberthg-docker-notes/docker%E7%AD%86%E8%A8%98-%E9%80%B2%E5%85%A5container-%E5%BB%BA%E7%AB%8B%E4%B8%A6%E6%93%8D%E4%BD%9C-postgresql-container-d221ba39aaec

docker pull postgres:14.3
docker create --name my-postgres -p 8080:5432 -e POSTGRES_PASSWORD=admin postgres:14.3
docker start my-postgres


docker exec my-postgres psql --help
docker exec my-postgres psql -V
docker exec my-postgres psql -U postgres -l
docker exec -it my-postgres psql -U postgres
\q


docker exec -it my-postgres bash
apt-getupdate
apt-get install net-tools
172.17.0.2

docker exec -it my-postgres psql -U postgres -c "create role <user-name> with login password '<password>';"

docker from scratch

 https://www.runoob.com/docker/docker-container-usage.html

Windows 11, Install docker Desktop, choose WSL2 not HyperV

docker run -itd -P --name banana ubuntu /bin/bash  # -d detached, -P all ports
docker exec -it banana ubuntu /bin/bash  # interactive, terminal
apt-get install curl  # this may cause Unable to locate package curl
apt-get update # then can install
apt-get install curl
apt-get install ssh
service ssh start
systemctl enable enable ssh
service ssh status
apt-get install net-tools
apt-get install netcat
apt-get install iputils-ping
ping 172.17.0.1  # this is the host
apt-get install telnet
telnet 172.17.0.1 8000

docker ps -a  # active

docker stop banana
docker commit banana banana02
docker run -itd -p 5432:5000 --name banana02 banana02 /bin/bash
docker exec -it banana02 /bin/bash
python3 -m http.server 5000
On host, firefox http://127.0.0.1:5432
On banana02, see 172.17.0.1 GET / 200

docker images

1、从已经创建的容器中更新镜像,并且提交这个镜像 (commit)

docker run -itd --name banana02 ubuntu:22.04 /bin/bash
docker exec -it banana02 /bin/bash
apt-get update
apt-get install -y iputils-ping netcat telnet
docker commit -m="John first commit" -a="John Doe author" banana02 ubuntu:v1
docker run -itd -P --name banana03 ubuntu:v1 /bin/bash
docker exec -it banana03 /bin/bash
nc -l 5000
On host, telnet 127.0.0.1 49154

2、使用 Dockerfile 指令来创建一个新的镜像 (Dockerfile)

cat Dockerfile
FROM    ubuntu:22.04
MAINTAINER      Fisher "fisher@sudops.com"
RUN     apt-get -y update
RUN     apt-get install -y iputils-ping netcat telnet
EXPOSE  22
EXPOSE  80
EXPOSE  5000

docker build -t ubuntu:v2 .
docker run -itd -p 5000:5000 -P --name banana04 ubuntu:v2 /bin/bash
docker exec -it banana04 /bin/bash
49159:22
5000:5000
49158:80
docker tag ubuntu:v2 ubuntu:v3





End






2022年12月1日 星期四

GDB with a crash file and usual commands (and also CLion)

The crash file could be just 10MB


Commands

sudo apport-unpack some.10MB.crash CoreDump

sudo chown -R user:user CoreDump/

cd ./CoreDump

gdb ./binary CoreDump


Commands

frame

up

down

bt

list

info locals

info args

print iter

print hashTable


CLion

Run > Open Core Dump

Core dump: The 200MB core dump file

Symbol file: The originating executable file

2007 to 2023 HP and Dell Servers Comparison

  HP Gen5 to Gen11  using ChatGPT HP ProLiant Gen Active Years CPU Socket Popular HP CPUs Cores Base Clock Max RAM Capacity Comparable Dell ...