Skip to content

Instantly share code, notes, and snippets.

@Na0ki
Last active June 3, 2025 13:24
Show Gist options
  • Save Na0ki/1f541bfb12956d5c56002f2bb40007a1 to your computer and use it in GitHub Desktop.
Save Na0ki/1f541bfb12956d5c56002f2bb40007a1 to your computer and use it in GitHub Desktop.
patchelfの挙動確認するのに使った色々
services:
task:
build:
context: .
dockerfile: Dockerfile.patchelfpoc
tty: true
stdin_open: true
working_dir: /working_dir
command: /bin/bash
volumes:
- ./src:/working_dir
FROM debian:bookworm
RUN apt-get update
RUN apt-get install -y gcc g++ make software-properties-common curl wget vim patchelf file
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
CMD ["/bin/bash"]
void func();
int main() {
func();
return 0;
}
build:
gcc -c -o main.o main.c
gcc -fPIC -shared -o libmylib1.so mylib1.c
gcc -fPIC -shared -o libmylib2.so mylib2.c
gcc -o main main.c -L. -lmylib1 -Wl,-rpath,.
link2:
patchelf --add-needed ./libmylib2.so main
read:
readelf -d main
#include <stdio.h>
void func(void) {
printf("Hello World!\n");
}
#include <stdio.h>
void func(void) {
printf("Bye World!\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment