[PATCH] D69607: Add a feature to explain why some file gets included to the linker's output

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 5 09:24:07 PST 2019


MaskRay added inline comments.


================
Comment at: lld/ELF/Explain.cpp:95
+
+  // Collect root objects.
+  for (InputFile *f : objectFiles)
----------------
pcc wrote:
> ruiu wrote:
> > pcc wrote:
> > > Hmm, object files aren't really gc roots, so this could give misleading output (e.g. `ld a.o b.o --explain a` with a.o containing `a: ret` and b.o containing `b: call a` with only b in dynsym won't report b.o). Also, it misses archives included with `--whole-archive`.
> > > 
> > > Shouldn't this be more similar to MarkLive.cpp? In other words, include dynsym and don't treat object files as roots.
> > I think object files are actually roots in this features sense if you do not pass `-gc-sections`, so we need to handle two different cases, `-no-gc-sections` and `-gc-sections`. How is this new code?
> Maybe I'm missing something, but I don't see where dynsyms are being added in the new code in the `--gc-sections` case,
We don't need to handle --init, --fini or .dynsym as opposed to MarkLive.cpp.

```
# c.s -> c.o
.globl _start
_start:
  ret

.section .text.foo,"ax"
call bar

# b.s -> b.o -> b.a
% cat b.s
.globl bar
bar:
  call foo

# a.s -> a.o -> a.a
.globl foo
foo:
  ret
```

For example, in `ld.lld c.o b.a a.a --gc-sections -o a`, neither b.a nor a.a is necessary (none of their sections is retained) but we still need to link in b.a and a.a before discarding their sections. The archive handling logic happens before garbage collection.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69607/new/

https://reviews.llvm.org/D69607





More information about the llvm-commits mailing list