[PATCH] D24750: [GC] Don't crash while processing Discarded sections
Davide Italiano via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 21 13:43:22 PDT 2016
davide added a comment.
The reason why gcc doesn't crash (and presumably also MSVC) is that this code is hitting UB.
`getFile() == nullptr`, but gcc decides to not crash, instead it returns a bogus pointer for the object pointed by `getFile()->getObj()`.
diff --git a/ELF/MarkLive.cpp b/ELF/MarkLive.cpp
index 4965377..0c6d510 100644
--- a/ELF/MarkLive.cpp
+++ b/ELF/MarkLive.cpp
@@ -81,6 +81,14 @@ static ResolvedReloc<ELFT> resolveReloc(InputSectionBase<ELFT> &Sec,
template <class ELFT>
static void forEachSuccessor(InputSection<ELFT> &Sec,
std::function<void(ResolvedReloc<ELFT>)> Fn) {
+
+ if (&Sec == &InputSection<ELFT>::Discarded) {
+ if (Sec.getFile() == nullptr) {
+ ELFFile<ELFT> &Obj = Sec.getFile()->getObj();
+ llvm::errs() << "Still alive: " << &Obj << "\n";
+ }
+ }
+
ELFFile<ELFT> &Obj = Sec.getFile()->getObj();
for (const typename ELFT::Shdr *RelSec : Sec.RelocSections) {
if (RelSec->sh_type == SHT_RELA) {
$ /home/davide/work/llvm/build-gcc/./bin/ld.lld -shared /home/davide/work/llvm/build-gcc/tools/lld/test/ELF/Output/comdat.s.tmp.o /home/davide/work/llvm/build-gcc/tools/lld/test/ELF/Output/comdat.s.tmp.o /home/davide/work/llvm/build-gcc/tools/lld/test/ELF/Output/comdat.s.tmp2.o -o /home/davide/work/llvm/build-gcc/tools/lld/test/ELF/Output/comdat.s.tmp --gc-sections
Still alive: 0x48
https://reviews.llvm.org/D24750
More information about the llvm-commits
mailing list