This is an archive of the discontinued LLVM Phabricator instance.

[LLD][ELF] - Remove dead code from ArchiveFile.
AbandonedPublic

Authored by grimar on Aug 2 2018, 3:14 AM.

Details

Summary

I believe this is NFC change, but posting on review just in case I am missing something.

Currently, the code uses Seen set to prevent fetching the archive files twice,
but I think it is impossible to face this situation. Because if we have lazy symbols
A1..An from object in archive AR, then after facing undefined symbol A1 in some regular object,
we will fetch() and resolve all symbols and will never call fetch() for symbols from archive AR again.

Diff Detail

Event Timeline

grimar created this revision.Aug 2 2018, 3:14 AM
ruiu added a comment.Aug 2 2018, 3:31 PM

I think this change is a bit dangerous to land because this patch removes the safeguard to not pull out the same object file more than once from an archive file. If our symbol resolution logic is as simple as you described, and if consistency between archive file index and actual object files in it is maintained for all input files, this change should be fine. But I think taking that risk is unnecessary. (I vaguely remember that there was a some problem if we don't have this code, but I can't remember it now.)

grimar added a comment.Aug 3 2018, 3:58 AM

Honestly, I am a bit upset about that our LLD coding style moved from "we do this because of that" to "we do this just in case, I do not remember why".
I'll try to dig why we did that initially.

ruiu added a comment.Aug 3 2018, 11:03 AM

No, that's not really the case. I strongly suspect that if you land this, you'll see some weird behavior in the wild.

pcc added a subscriber: pcc.Aug 6 2018, 1:05 PM

The issue is that if two object files depend on one another, we can end up in a situation where SymbolTable::fetchLazy is called recursively multiple times on the same object file, so we need to make sure to do nothing on the second call. Reproducer:

$ cat a.s
.globl a, b
a:
$ cat b.s
.globl a, b
b:
$ as -o a.o a.s
$ as -o b.o b.s
$ ar cru foo.a a.o b.o
$ ld.lld -eb foo.a -m elf_x86_64

With your patch I get:

ld.lld: error: duplicate symbol: b
>>> defined at b.o:(.text+0x0) in archive foo.a
>>> defined at b.o:(.text+0x0) in archive foo.a
In D50174#1189892, @pcc wrote:

The issue is that if two object files depend on one another, we can end up in a situation where SymbolTable::fetchLazy is called recursively multiple times on the same object file, so we need to make sure to do nothing on the second call. Reproducer:

$ cat a.s
.globl a, b
a:
$ cat b.s
.globl a, b
b:
$ as -o a.o a.s
$ as -o b.o b.s
$ ar cru foo.a a.o b.o
$ ld.lld -eb foo.a -m elf_x86_64

With your patch I get:

ld.lld: error: duplicate symbol: b
>>> defined at b.o:(.text+0x0) in archive foo.a
>>> defined at b.o:(.text+0x0) in archive foo.a

Thanks a lot for the reproducer, Peter! I'll check it and add a test to LLD.

grimar abandoned this revision.Aug 7 2018, 1:50 AM

Abandoning this patch, the test case for the code was committed in rL339114.