aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Target/TargetLoweringObjectFile.cpp
diff options
context:
space:
mode:
authorLeonard Chan <leonardchan@google.com>2021-02-10 09:59:36 -0800
committerLeonard Chan <leonardchan@google.com>2021-02-18 15:39:00 -0800
commitc77659e5494e4aa942bf0bc709b1779931dd30a8 (patch)
tree8d01772e714404683b7737a24d16351567e191ff /llvm/lib/Target/TargetLoweringObjectFile.cpp
parentafdfdc4bcf1e3d9d8596b701da69f2309e7bf697 (diff)
downloadllvm-c77659e5494e4aa942bf0bc709b1779931dd30a8.zip
llvm-c77659e5494e4aa942bf0bc709b1779931dd30a8.tar.gz
llvm-c77659e5494e4aa942bf0bc709b1779931dd30a8.tar.bz2
[llvm][IR] Do not place constants with static relocations in a mergeable section
This patch provides two major changes: 1. Add getRelocationInfo to check if a constant will have static, dynamic, or no relocations. (Also rename the original needsRelocation to needsDynamicRelocation.) 2. Only allow a constant with no relocations (static or dynamic) to be placed in a mergeable section. This will allow unused symbols that contain static relocations and happen to fit in mergeable constant sections (.rodata.cstN) to instead be placed in unique-named sections if -fdata-sections is used and subsequently garbage collected by --gc-sections. See https://lists.llvm.org/pipermail/llvm-dev/2021-February/148281.html. Differential Revision: https://reviews.llvm.org/D95960
Diffstat (limited to 'llvm/lib/Target/TargetLoweringObjectFile.cpp')
-rw-r--r--llvm/lib/Target/TargetLoweringObjectFile.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/llvm/lib/Target/TargetLoweringObjectFile.cpp b/llvm/lib/Target/TargetLoweringObjectFile.cpp
index 239f12c..4efac23 100644
--- a/llvm/lib/Target/TargetLoweringObjectFile.cpp
+++ b/llvm/lib/Target/TargetLoweringObjectFile.cpp
@@ -290,7 +290,8 @@ SectionKind TargetLoweringObjectFile::getKindForGlobal(const GlobalObject *GO,
// consideration when it tries to merge entries in the section.
Reloc::Model ReloModel = TM.getRelocationModel();
if (ReloModel == Reloc::Static || ReloModel == Reloc::ROPI ||
- ReloModel == Reloc::RWPI || ReloModel == Reloc::ROPI_RWPI)
+ ReloModel == Reloc::RWPI || ReloModel == Reloc::ROPI_RWPI ||
+ !C->needsDynamicRelocation())
return SectionKind::getReadOnly();
// Otherwise, the dynamic linker needs to fix it up, put it in the