MC/Mach-O: Factor out isSymbolLinkerVisible method; "linker visible" is a made up...
authorDaniel Dunbar <daniel@zuster.org>
Fri, 19 Mar 2010 03:18:09 +0000 (03:18 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Fri, 19 Mar 2010 03:18:09 +0000 (03:18 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98923 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCAssembler.h
lib/MC/MCAssembler.cpp

index 1d8051fdb060736c59b6d7eba46a81da23aab748..620b4f4ec21e15bbd270a01f1385f42f7eb69780 100644 (file)
@@ -636,6 +636,12 @@ private:
 
   // FIXME: Make protected once we factor out object writer classes.
 public:
+  /// Check whether a particular symbol is visible to the linker and is required
+  /// in the symbol table, or whether it can be discarded by the assembler. This
+  /// also effects whether the assembler treats the label as potentially
+  /// defining a separate atom.
+  bool isSymbolLinkerVisible(const MCSymbolData *SD) const;
+
   /// Evaluate a fixup to a relocatable expression and the value which should be
   /// placed into the fixup.
   ///
index 51b12734afeefe385c6e649eedcaad3813f30534..065c49e72823e3e26db470790f50dcef96028fcc 100644 (file)
@@ -673,11 +673,8 @@ public:
            ie = Asm.symbol_end(); it != ie; ++it) {
       const MCSymbol &Symbol = it->getSymbol();
 
-      // Ignore assembler temporaries.
-      if (it->getSymbol().isTemporary() &&
-          (!it->getFragment() ||
-           !Asm.getBackend().doesSectionRequireSymbols(
-             it->getFragment()->getParent()->getSection())))
+      // Ignore non-linker visible symbols.
+      if (!Asm.isSymbolLinkerVisible(it))
         continue;
 
       if (!it->isExternal() && !Symbol.isUndefined())
@@ -712,11 +709,8 @@ public:
            ie = Asm.symbol_end(); it != ie; ++it) {
       const MCSymbol &Symbol = it->getSymbol();
 
-      // Ignore assembler temporaries.
-      if (it->getSymbol().isTemporary() &&
-          (!it->getFragment() ||
-           !Asm.getBackend().doesSectionRequireSymbols(
-             it->getFragment()->getParent()->getSection())))
+      // Ignore non-linker visible symbols.
+      if (!Asm.isSymbolLinkerVisible(it))
         continue;
 
       if (it->isExternal() || Symbol.isUndefined())
@@ -1016,6 +1010,20 @@ MCAssembler::MCAssembler(MCContext &_Context, TargetAsmBackend &_Backend,
 MCAssembler::~MCAssembler() {
 }
 
+bool MCAssembler::isSymbolLinkerVisible(const MCSymbolData *SD) const {
+  // Non-temporary labels should always be visible to the linker.
+  if (!SD->getSymbol().isTemporary())
+    return true;
+
+  // Absolute temporary labels are never visible.
+  if (!SD->getFragment())
+    return false;
+
+  // Otherwise, check if the section requires symbols even for temporary labels.
+  return getBackend().doesSectionRequireSymbols(
+    SD->getFragment()->getParent()->getSection());
+}
+
 bool MCAssembler::EvaluateFixup(const MCAsmLayout &Layout, MCAsmFixup &Fixup,
                                 MCDataFragment *DF,
                                 MCValue &Target, uint64_t &Value) const {