Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@MaskRay
Last active September 10, 2023 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MaskRay/c03a90922003df666551589f1629df22 to your computer and use it in GitHub Desktop.
Save MaskRay/c03a90922003df666551589f1629df22 to your computer and use it in GitHub Desktop.
Test dso_local changes (e.g. -fno-semantic-interposition, -fno-plt, -fno-direct-access-external-data)
#!/bin/zsh
CC=/tmp/Rel/bin/clang
if [[ -n $1 ]]; then
update=1
echo updated
else
update=
fi
if [[ ! -e meow.cc ]]; then
cat >meow.cc <<e
int var;
extern int ext_var;
__attribute__((visibility("hidden"))) extern int ext_var_hidden;
__attribute__((weak)) extern int ext_var_weak;
__attribute__((weak, visibility("hidden"))) extern int ext_var_weak_hidden;
#ifdef _WIN32
__declspec(dllimport) extern int imp_var;
#endif
int func(void) { return 0; }
__attribute__((visibility("hidden"))) int func_hidden(void) { return 0; }
__attribute__((weak)) int func_weak(void) { return 0; }
__attribute__((visibility("hidden"), weak)) int func_hidden_weak(void) { return 0; }
int ext_func(void);
__attribute__((visibility("hidden"))) int ext_func_hidden(void);
__attribute__((weak)) int ext_func_weak(void);
__attribute__((visibility("hidden"), weak)) int ext_func_hidden_weak(void);
int (*fptr)(void);
int foo() {
int s = var + ext_var + ext_var_hidden + ext_var_weak + ext_var_weak_hidden;
#ifdef _WIN32
s = imp_var;
#endif
return s + func() + func_hidden() + func_weak() + func_hidden_weak() +
ext_func() + ext_func_hidden() + ext_func_weak() + ext_func_hidden_weak() + fptr();
}
void *func_addr() { return (void*)func; }
void *func_hidden_addr() { return (void*)func_hidden; }
void *func_weak_addr() { return (void*)func_weak; }
void *func_hidden_weak_addr() { return (void*)func_hidden_weak; }
void *ext_func_addr() { return (void*)ext_func; }
void *ext_func_hidden_addr() { return (void*)ext_func_hidden; }
void *ext_func_weak_addr() { return (void*)ext_func_weak; }
void *ext_func_hidden_weak_addr() { return (void*)ext_func_hidden_weak; }
void test_memcpy(void *dst, const void *src, unsigned long len) {
__builtin_memcpy(dst, src, len);
}
e
fi
run() {
if [[ -n $update ]]; then
$CC "${@:2}" -S meow.cc -o $1.s
else
if $CC "${@:2}" -S meow.cc -o - | diff -u $1.s -; then
:
else
echo $@
fi
fi
}
run nopic -fno-pic
run pie -fpie
run pic -fpic
run pic.sem -fpic -fsemantic-interposition
run pic.nosem -fpic -fno-semantic-interposition
run nopic.noplt -fno-plt
run pic.noplt -fpic -fno-plt
run nopic.got -fno-direct-access-external-data
run nopic.asan -fsanitize=address
run pic.asan -fpic -fsanitize=address
run i386.nopic -fno-pic -m32
run i386.pie -fpie -m32
run i386.pic -fpic -m32
run i386.pic.sem -fpic -fsemantic-interposition -m32
run i386.pic.nosem -fpic -fno-semantic-interposition -m32
run i386.nopic.noplt -fno-plt -m32
run i386.pic.noplt -fpic -fno-plt -m32
run i386.nopic.got -fno-direct-access-external-data -m32
run i386.nopic.asan -fsanitize=address -m32
run i386.pic.asan -fpic -fsanitize=address -m32
run arm.nopic -fno-pic --target=armv7-linux-gnueabi
run arm.pie -fpie --target=armv7-linux-gnueabi
run arm.pic -fpic --target=armv7-linux-gnueabi
run arm.pic.sem -fpic -fsemantic-interposition --target=armv7-linux-gnueabi
run arm.pic.nosem -fpic -fno-semantic-interposition --target=armv7-linux-gnueabi
run a64.nopic -fno-pic --target=aarch64
run a64.pie -fpie --target=aarch64
run a64.pic -fpic --target=aarch64
run a64.pic.sem -fpic -fsemantic-interposition --target=aarch64
run a64.pic.nosem -fpic -fno-semantic-interposition --target=aarch64
run darwin.arm.pic --target=arm-darwin -fpic -w
run darwin.arm.nopic --target=arm-darwin -fno-pic -w
run darwin.arm.dyn --target=arm-darwin -mdynamic-no-pic -w
run darwin.arm.pic.asan --target=x86_64-darwin -fpic -fsanitize=address -w
run darwin.x86.pic --target=x86_64-darwin -w
run darwin.x86.pic.asan --target=x86_64-darwin -fsanitize=address -w
# Mach-O firmware hack
run win.macho --target=x86_64-win32-macho
run win.macho.nopic --target=x86_64-win32-macho -fno-pic
run win.x86 --target=x86_64-windows
run win.x86.asan --target=x86_64-windows -fsanitize=address
run win.x86.coverage --target=x86_64-windows -fprofile-instr-generate
run win.x86.pgo --target=x86_64-windows -fprofile-generate
run mingw.x86 --target=x86_64-windows-gnu
run mingw.x86.nopic --target=x86_64-windows-gnu -fno-pic
run mingw.x86.asan --target=x86_64-windows-gnu -fsanitize=address
run mingw.x86.coverage --target=x86_64-windows-gnu -fprofile-instr-generate
run mingw.x86.pgo --target=x86_64-windows-gnu -fprofile-generate
run win.arm --target=arm-windows
run win.arm.asan --target=arm-windows -fsanitize=address
run win.a64 --target=aarch64-windows
run win.a64.asan --target=aarch64-windows -fsanitize=address
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment