viralcode / address-sanitizer

Automatically exported from code.google.com/p/address-sanitizer
1 stars 0 forks source link

globals are broken if PIC and nonPIC objects are mixed: #3

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Currently, we can no mix PIC and non-PIC objects if globals are instrumented

% head a.cc b.cc
==> a.cc <==
#include <stdio.h>
int* CCC = new int;

int *zoo() {
  printf("z1 %p\n", &CCC);
  return CCC;
}

==> b.cc <==
#include <stdio.h>

extern int *CCC;
extern int *zoo();

int main(int argc, char** argv) {
  printf("z2 %p\n", &CCC);
  zoo();
}

./my_clang++ -O2 a.cc -fasan -c -fPIC && gcc -shared a.o -o a.so && 
./my_clang++ -fasan -O2  b.cc a.so -Wl,-rpath=. && ./a.out 
z2 0x60e180
z1 0x7fc063fa2060

# both numbers should be the equal

Original issue reported on code.google.com by konstant...@gmail.com on 29 Jul 2011 at 4:03

GoogleCodeExporter commented 9 years ago
Interesting warning with slightly different repro: 

% head a.c b.c 
==> a.c <==
int CCC;
int *zoo() {
  return &CCC;
}

==> b.c <==
#include <stdio.h>
extern int CCC;
extern int *zoo();
int main(int argc, char** argv) {
  printf("main %p\n", &CCC);
  printf("lib  %p\n", zoo());
}
% ./my_clang -O2 a.c -fasan -c -fPIC && gcc -shared a.o -o a.so && gcc -c b.c 
&& ./my_clang++ -fasan -O2  b.o a.so -Wl,-rpath=. && ./a.out
./a.out: Symbol `CCC' causes overflow in R_X86_64_PC32 relocation
main 0x2829c40
lib  0x7fd102829c40

Original comment by konstant...@gmail.com on 6 Oct 2011 at 3:49

GoogleCodeExporter commented 9 years ago
GNU ld gives even more interesting warning: 
/usr/bin/ld: a.o: relocation R_X86_64_PC32 against symbol `CCC' can not be used 
when making a shared object; recompile with -fPIC

/usr/bin/ld: final link failed: Bad value

Original comment by konstant...@gmail.com on 6 Oct 2011 at 7:53

GoogleCodeExporter commented 9 years ago
GNU ld gives even more interesting warning: 
/usr/bin/ld: a.o: relocation R_X86_64_PC32 against symbol `CCC' can not be used 
when making a shared object; recompile with -fPIC

/usr/bin/ld: final link failed: Bad value

Original comment by konstant...@gmail.com on 6 Oct 2011 at 8:09

GoogleCodeExporter commented 9 years ago
fixed by r849. 
This was caused by http://llvm.org/bugs/show_bug.cgi?id=11081
The fix is to not use GLobalAlias at all (we don't seem to need it anyway)

Original comment by konstant...@gmail.com on 6 Oct 2011 at 10:00