Skip to content

Instantly share code, notes, and snippets.

@justinian
Last active August 11, 2023 04:18
Show Gist options
  • Select an option

  • Save justinian/ed2b2b850051135a51a3d38888935f20 to your computer and use it in GitHub Desktop.

Select an option

Save justinian/ed2b2b850051135a51a3d38888935f20 to your computer and use it in GitHub Desktop.
Clang and _GLOBAL_OFFSET_TABLE_
unsigned long SOME_GLOBAL = 123;
extern unsigned long _GLOBAL_OFFSET_TABLE_ [];
extern unsigned long SOME_GLOBAL;
int main() {
auto foo1 = reinterpret_cast<unsigned long*>(&_GLOBAL_OFFSET_TABLE_);
auto foo2 = reinterpret_cast<unsigned long*>( _GLOBAL_OFFSET_TABLE_);
auto bar1 = &SOME_GLOBAL;
auto bar2 = reinterpret_cast<unsigned long*>(SOME_GLOBAL);
return 0;
}
#CC = /home/justin/.local/lib/jsix/toolchains/llvm-13/bin/clang++
#LD = /home/justin/.local/lib/jsix/toolchains/llvm-13/bin/ld.lld
#CC = g++
#LD = ld
#CC = clang++-13
#LD = clang++-13
#LD = ld.lld-13
CC = clang++-16
LD = ld.lld-16
got: foo.o bar.o
${LD} -pie -o $@ $^
%.o: %.cpp
${CC} -c -g -fpie -o $@ $^
dump: got
${CC} --version
objdump -M intel -DS -j .text $^
clean:
-rm *.o got
.PHONY: rip clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment