Correctly detect if a symbol uses a reserved section index or not.
[oota-llvm.git] / lib / MC / ELFObjectWriter.cpp
index eb8b9bfe0ca9f46c571e4389a67194eed1230ef0..7c2135b2487c20857b46eae7c6a6195ca3384b03 100644 (file)
@@ -612,13 +612,15 @@ void ELFObjectWriter::WriteSymbol(SymbolTableWriter &Writer, ELFSymbolData &MSD,
   MCSymbolData &Data =
     Layout.getAssembler().getSymbolData(OrigData.getSymbol().AliasedSymbol());
 
-  bool IsReserved = Data.isCommon() || Data.getSymbol().isAbsolute() ||
-    Data.getSymbol().isVariable();
+  const MCSymbol *Base = getBaseSymbol(Layout, OrigData.getSymbol());
+
+  // This has to be in sync with when computeSymbolTable uses SHN_ABS or
+  // SHN_COMMON.
+  bool IsReserved = !Base || OrigData.isCommon();
 
   // Binding and Type share the same byte as upper and lower nibbles
   uint8_t Binding = MCELF::GetBinding(OrigData);
   uint8_t Type = MCELF::GetType(OrigData);
-  const MCSymbol *Base = getBaseSymbol(Layout, OrigData.getSymbol());
   if (Base) {
     MCSymbolData BaseSD = Layout.getAssembler().getSymbolData(*Base);
     Type = mergeTypeForSet(Type, MCELF::GetType(BaseSD));