Fixes the lld side problem of PR43147.
If st_link(A)=B, and A has the SHF_LINK_ORDER flag, we may dereference
a null pointer if B is garbage collected.
The added test section-metadata.s also tests -r to improve -r + SHF_LINK_ORDER coverage.
Differential D67754
[ELF] Fix two null pointer dereferences related to SHF_LINK_ORDER with --gc-sections MaskRay on Sep 19 2019, 3:30 AM. Authored by
Details Fixes the lld side problem of PR43147. If st_link(A)=B, and A has the SHF_LINK_ORDER flag, we may dereference The added test section-metadata.s also tests -r to improve -r + SHF_LINK_ORDER coverage.
Diff Detail
Event TimelineComment Actions Two questions:
(https://bugs.llvm.org/show_bug.cgi?id=43147#c8)
Comment Actions This will definitely avoid a crash but I'm not sure if a program that can trigger the crash is well defined under garbage collection. For a section A with link order dependency on section B, with A live and B not live, there is a requirement to order section B with respect to the address of section A, and we can't know what the address is if B has been garbage collected. Making an arbitrary choice for the address will work for cases where removing B means that the order of A doesn't matter, however if the order of A does matter then we could get a run-time error. I personally favour an error message, but I suppose a warning that the linker has made an arbitrary choice, or disabled garbage collection, could also work. Comment Actions I agree an error is the way to go. I had started to work on this patch before I read Peter's comment...
Yes. I highly suspect the sanitizer has a bug. Whether or not it is a real bug, @manojgupta has to use --no-gc-sections.
I thought ld.bfd would accept such cases. It accepts section-metadata.s in this patch but rejects https://bugs.llvm.org/show_bug.cgi?id=43147#c8 Abandoned. We should go with D67761. |