From 9c5d64b901cf3b056edf17c9960ae54338a4bd52 Mon Sep 17 00:00:00 2001 From: Simon Dardis Date: Wed, 16 Aug 2017 12:18:04 +0000 Subject: [mips] Handle variables with an explicit section and interactions with .sdata, .sbss If a variable has an explicit section such as .sdata or .sbss, it is placed in that section and accessed in a gp relative manner. This overrides the global -G setting. Otherwise if a variable has a explicit section attached to it, such as '.rodata' or '.mysection', it is not placed in the small data section. This also overrides the global -G setting. Reviewers: atanasyan, nitesh.jain Differential Revision: https://reviews.llvm.org/D36616 llvm-svn: 311001 --- llvm/lib/Target/Mips/MipsTargetObjectFile.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'llvm/lib/Target') diff --git a/llvm/lib/Target/Mips/MipsTargetObjectFile.cpp b/llvm/lib/Target/Mips/MipsTargetObjectFile.cpp index 3bf32e81d57..9db6b7b1bcd 100644 --- a/llvm/lib/Target/Mips/MipsTargetObjectFile.cpp +++ b/llvm/lib/Target/Mips/MipsTargetObjectFile.cpp @@ -106,6 +106,22 @@ IsGlobalInSmallSectionImpl(const GlobalObject *GO, if (!GVA) return false; + // If the variable has an explicit section, it is placed in that section but + // it's addressing mode may change. + if (GVA->hasSection()) { + StringRef Section = GVA->getSection(); + + // Explicitly placing any variable in the small data section overrides + // the global -G value. + if (Section == ".sdata" || Section == ".sbss") + return true; + + // Otherwise reject accessing it through the gp pointer. There are some + // historic cases which GCC doesn't appear to respect any more. These + // are .lit4, .lit8 and .srdata. For the moment reject these as well. + return false; + } + // Enforce -mlocal-sdata. if (!LocalSData && GVA->hasLocalLinkage()) return false; -- cgit v1.2.3