[PATCH] D19040: Remove unnecessary load via GOT when accessing globals with PIE in x86_64
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 21 11:33:18 PDT 2016
rnk added inline comments.
================
Comment at: lib/Target/X86/X86Subtarget.cpp:62-63
@@ +61,4 @@
+// Executable (PIE) where its definition cannot be interposed.
+bool X86Subtarget::
+isGlobalDefinedInPIE(const GlobalValue *GV, const TargetMachine &TM) const {
+ return TM.Options.PositionIndependentExecutable &&
----------------
This isn't the usual formatting, consider running clang-format
================
Comment at: lib/Target/X86/X86Subtarget.cpp:65-67
@@ +64,5 @@
+ return TM.Options.PositionIndependentExecutable &&
+ !GV->isDeclaration() &&
+ (!GV->isInterposable() ||
+ GlobalValue::isWeakLinkage(GV->getLinkage()));
+}
----------------
After doing some experiments, I think the predicate we want here is really `TM.Options.PositionIndependentExecutable && !GV->isDeclarationForLinker()`.
Basically, once you know you are looking at a symbol definition that will become part of an executable, the only thing that can replace it is another definition within the executable. The glibc loader does *not* appear to replace weak symbols in an executable with strong symbols from a DSO. I mistakenly thought it would work the same way the linker does, where strong symbols beat weak symbols.
http://reviews.llvm.org/D19040
More information about the llvm-commits
mailing list