Closed yaghmr closed 2 years ago
Additional information: /bin/ls
is stripped
$ file /bin/ls /bin/ls: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/l, for GNU/Linux 3.2.0, BuildID[sha1]=9567f9a28e66f4d7ec4baf31cfbf68d0410f0ae6, stripped
I have the same issue - but only on a few files targets, e.g. libxml2-2.9.2 (others work, all working and non working compiled freshly with the same gcc):
# gcc xmllint.s -o xmllint.bin -lz -lm -lpthread -llzma
/bin/ld: /tmp/ccMboylz.o:(.data+0x9d8): undefined reference to `.LC15520'
/bin/ld: /tmp/ccMboylz.o:(.data+0x9e0): undefined reference to `.LC151b0'
/bin/ld: /tmp/ccMboylz.o:(.data+0x9e8): undefined reference to `.LC151b0'
/bin/ld: /tmp/ccMboylz.o:(.data+0x9f0): undefined reference to `.LC15270'
collect2: error: ld returned 1 exit status
This is with gcc 7 and gcc 9.
Note that it is gcc/C code and not stripped:
# file xmllint
xmllint: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=398b42c27ccf32335def98f5ae8110f2eb2e7a6b, for GNU/Linux 3.2.0, with debug_info, not stripped
Thanks for the report! Your file output on xmllint seems good to me. Could you please link me/attach a copy of xmllint to help debug? (or instructions to build the same would be helpful).
It is libxml2-2.9.2 and compiled with "./configure --disable-shared"
I have the binary attached as a gz archive:
@sushant94 can I assist you further in fixing this?
@vanhauser-thc I've isolated the issue. We seem to not handle globals initialized to imported functions correctly. Working on a fix.
I too encountered a similar issue. I am providing the output below (including the output from the intrumentation step, if it may be of more help):
(retro) sanjay@sanjay-lap:~/tools/retrowrite$ ./retrowrite --asan ~/TeachingCodeExamples/mallocEx ~/TeachingCodeExamples/mallocEx-san.s
[*] Relocations for a section that's not loaded: .rela.dyn
[*] Relocations for a section that's not loaded: .rela.plt
[x] Could not replace value in .init_array
[x] Couldn't find valid section 200d90
[x] Couldn't find valid section 200fd8
[x] Couldn't find valid section 200fe0
[x] Couldn't find valid section 200fe8
[x] Couldn't find valid section 200ff0
[x] Couldn't find valid section 200ff8
[*] Analyzing free registers
[*] Instrumented: 39 locations
Number of free registers: [1, 2, 2, 2, 1, 2, 1, 3, 4, 3, 4, 3, 2, 1, 1, 2, 2, 1, 1, 2, 1, 2, 4, 3, 2, 3, 1, 2, 1, 0, 1, 0, 1, 0, 3, 2, 1, 2, 2]
{"rax": 26, "rflags": 39, "rdi": 22, "rdx": 14, "rsi": 9}
rflags live: 0, rflags + 0 regs: 0, rflags + rax: 0, rflags + >= 1 reg: 0
(retro) sanjay@sanjay-lap:~/tools/retrowrite$ gcc ~/TeachingCodeExamples/mallocEx-san.s -lasan -o ~/TeachingCodeExamples/malloc-instru
/tmp/ccPfQZnK.o: In function `asan.module_ctor':
(.text+0x7a2): undefined reference to `__asan_init_v4'
collect2: error: ld returned 1 exit status
(retro) sanjay@sanjay-lap:~/tools/retrowrite$
@tosanjay Your error comes from the fact the version of asan was changed. I believe this is fixed in the latest development version, but in the mean time you can fix your example by running the following:
sed -i 's/asan_init_v4/asan_init/g' ~/TeachingCodeExamples/mallocEx-san.s
between the retrowrite command (rewrite step) and reassembling with gcc. You should then be able to link successfully.
@tosanjay Your error comes from the fact the version of asan was changed. I believe this is fixed in the latest development version, but in the mean time you can fix your example by running the following:
sed -i 's/asan_init_v4/asan_init/g' ~/TeachingCodeExamples/mallocEx-san.s
between the retrowrite command (rewrite step) and reassembling with gcc. You should then be able to link successfully.
Thanks @diagprov It worked!
I'm trying this command
$ gcc ls-basan-instrumented.s -lasan -o ls-basan-instrumented
and I get these errors:
my GCC version is:
gcc version 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04.1)