[lld] r259474 - ELF: Simplify and add comments.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 1 23:50:18 PST 2016
Author: ruiu
Date: Tue Feb 2 01:50:18 2016
New Revision: 259474
URL: http://llvm.org/viewvc/llvm-project?rev=259474&view=rev
Log:
ELF: Simplify and add comments.
Modified:
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=259474&r1=259473&r2=259474&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Tue Feb 2 01:50:18 2016
@@ -387,15 +387,23 @@ void Writer<ELFT>::scanRelocs(
continue;
}
- // Here we are creating a relocation for the dynamic linker based on
- // a relocation from an object file, but some relocations need no
- // load-time fixup when the final target is known. Skip such relocation.
- bool CBP = canBePreempted(Body, /*NeedsGot=*/false);
- bool Dynrel = Config->Shared && !Target->isRelRelative(Type) &&
- !Target->isSizeRel(Type);
- if (CBP)
+ // We get here if a program was not compiled as PIC.
+ if (canBePreempted(Body, /*NeedsGot=*/false)) {
Body->setUsedInDynamicReloc();
- if (CBP || Dynrel)
+ Out<ELFT>::RelaDyn->addReloc({&C, &RI});
+ continue;
+ }
+
+ // If we get here, the code we are handling is not PIC. We need to copy
+ // relocations from object files to the output file, so that the
+ // dynamic linker can fix up addresses. But there are a few exceptions.
+ // If the relocation will not change at runtime, we don't need to copy
+ // them. For example, we don't copy PC-relative relocations because
+ // the distance between two symbols won't change whereever they are
+ // loaded. Likewise, if we are linking an executable, it will be loaded
+ // at a fixed address, so we don't copy relocations.
+ if (Config->Shared && !Target->isRelRelative(Type) &&
+ !Target->isSizeRel(Type))
Out<ELFT>::RelaDyn->addReloc({&C, &RI});
}
}
More information about the llvm-commits
mailing list