Created
July 30, 2019 20:33
-
-
Save rprichard/e5ad0cfa10f6b75925ded3709117500f to your computer and use it in GitHub Desktop.
Demonstrate misalignment when (p_vaddr % p_align) != 0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
CLANG=/x/llvm-upstream/stage1/bin/clang | |
$CLANG -target aarch64-linux-gnu -fpic -shared libtls.c -fuse-ld=lld -o libtls.so | |
$CLANG -target aarch64-linux-gnu main.c -ldl -o main -Wl,-rpath,'$ORIGIN' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
__thread char tlsvar1[1] = { 1 }; | |
__thread char tlsvar2[0x100] __attribute__((aligned(0x100))); | |
void dump(void) { | |
printf("&tlsvar1 = %p\n", &tlsvar1); | |
printf("&tlsvar2 = %p\n", &tlsvar2); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <assert.h> | |
#include <dlfcn.h> | |
int main() { | |
void* lib = dlopen("libtls.so", RTLD_NOW); | |
assert(lib); | |
void (*dump)(void) = dlsym(lib, "dump"); | |
assert(dump); | |
dump(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment