Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ramosian-glider opened this issue Aug 31, 2015 · 5 comments
Closed

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

ramosian-glider opened this issue Aug 31, 2015 · 5 comments

Comments

@ramosian-glider
Copy link
Member

Originally reported on Google Code with ID 3

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

Reported by konstantin.s.serebryany on 2011-07-29 16:03:45

@ramosian-glider
Copy link
Member Author

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

Reported by konstantin.s.serebryany on 2011-10-06 15:49:50

@ramosian-glider
Copy link
Member Author

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

Reported by konstantin.s.serebryany on 2011-10-06 19:53:32

@ramosian-glider
Copy link
Member Author

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

Reported by konstantin.s.serebryany on 2011-10-06 20:09:59

@ramosian-glider
Copy link
Member Author

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)

Reported by konstantin.s.serebryany on 2011-10-06 22:00:00

  • Status changed: Fixed

@ramosian-glider
Copy link
Member Author

Adding Project:AddressSanitizer as part of GitHub migration.

Reported by ramosian.glider on 2015-07-30 09:12:57

  • Labels added: ProjectAddressSanitizer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant