Skip to content

Instantly share code, notes, and snippets.

@goodell
Created January 9, 2013 23:55
Show Gist options
  • Save goodell/4498137 to your computer and use it in GitHub Desktop.
Save goodell/4498137 to your computer and use it in GitHub Desktop.
my (failed) attempt at creating a small reproducer for macports bug #36654 (https://trac.macports.org/ticket/36654)
__thread int t = 0xdeadbeef;
int foo(void)
{
return t;
}
clang -g -Wall -dynamiclib -o libbar.dylib bar.c
clang -g -Wall -Wl,-no_pie foo.c -L. -lbar
(the above command was expected to segfault the linker)
./a.out
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <sys/wait.h>
extern int foo(void);
extern __thread int t;
int main(int argc, char *argv[])
{
printf("before change %#x\n", foo());
t = 0xcafebabe;
printf("after change %#x\n", foo());
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment