[lld] r318097 - [MIPS] Set STO_MIPS_MICROMIPS flag and less-significant bit for microMIPS symbols

Simon Atanasyan via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 13 14:40:36 PST 2017


Author: atanasyan
Date: Mon Nov 13 14:40:36 2017
New Revision: 318097

URL: http://llvm.org/viewvc/llvm-project?rev=318097&view=rev
Log:
[MIPS] Set STO_MIPS_MICROMIPS flag and less-significant bit for microMIPS symbols

microMIPS symbols including microMIPS PLT records created for regular
symbols needs to be marked by STO_MIPS_MICROMIPS flag in a symbol table.
Additionally microMIPS entries in a dynamic symbol table should have
configured less-significant bit. That allows to escape teaching a
dynamic linker about microMIPS symbols.

Modified:
    lld/trunk/ELF/Arch/Mips.cpp
    lld/trunk/ELF/Arch/MipsArchTree.cpp
    lld/trunk/ELF/SyntheticSections.cpp
    lld/trunk/ELF/Writer.h
    lld/trunk/test/ELF/mips-micro-plt.s

Modified: lld/trunk/ELF/Arch/Mips.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/Mips.cpp?rev=318097&r1=318096&r2=318097&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/Mips.cpp (original)
+++ lld/trunk/ELF/Arch/Mips.cpp Mon Nov 13 14:40:36 2017
@@ -191,8 +191,6 @@ template <class ELFT> RelType MIPS<ELFT>
   return RelativeRel;
 }
 
-static bool isMicroMips() { return Config->EFlags & EF_MIPS_MICROMIPS; }
-
 template <class ELFT>
 void MIPS<ELFT>::writeGotPlt(uint8_t *Buf, const Symbol &) const {
   uint64_t VA = InX::Plt->getVA();

Modified: lld/trunk/ELF/Arch/MipsArchTree.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/MipsArchTree.cpp?rev=318097&r1=318096&r2=318097&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/MipsArchTree.cpp (original)
+++ lld/trunk/ELF/Arch/MipsArchTree.cpp Mon Nov 13 14:40:36 2017
@@ -364,6 +364,8 @@ bool elf::isMipsN32Abi(const InputFile *
   }
 }
 
+bool elf::isMicroMips() { return Config->EFlags & EF_MIPS_MICROMIPS; }
+
 bool elf::isMipsR6() {
   uint32_t Arch = Config->EFlags & EF_MIPS_ARCH;
   return Arch == EF_MIPS_ARCH_32R6 || Arch == EF_MIPS_ARCH_64R6;

Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=318097&r1=318096&r2=318097&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Mon Nov 13 14:40:36 2017
@@ -1621,7 +1621,16 @@ template <class ELFT> void SymbolTableSe
       Symbol *Sym = Ent.Sym;
       if (Sym->isInPlt() && Sym->NeedsPltAddr)
         ESym->st_other |= STO_MIPS_PLT;
-
+      if (isMicroMips()) {
+        // Set STO_MIPS_MICROMIPS flag and less-significant bit for
+        // defined microMIPS symbols and shared symbols with PLT record.
+        if ((Sym->isDefined() && (Sym->StOther & STO_MIPS_MICROMIPS)) ||
+            (Sym->isShared() && Sym->NeedsPltAddr)) {
+          if (StrTabSec.isDynamic())
+            ESym->st_value |= 1;
+          ESym->st_other |= STO_MIPS_MICROMIPS;
+        }
+      }
       if (Config->Relocatable)
         if (auto *D = dyn_cast<Defined>(Sym))
           if (isMipsPIC<ELFT>(D))

Modified: lld/trunk/ELF/Writer.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.h?rev=318097&r1=318096&r2=318097&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.h (original)
+++ lld/trunk/ELF/Writer.h Mon Nov 13 14:40:36 2017
@@ -54,6 +54,7 @@ uint8_t getMipsFpAbiFlag(uint8_t OldFlag
                          llvm::StringRef FileName);
 
 bool isMipsN32Abi(const InputFile *F);
+bool isMicroMips();
 bool isMipsR6();
 } // namespace elf
 } // namespace lld

Modified: lld/trunk/test/ELF/mips-micro-plt.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-micro-plt.s?rev=318097&r1=318096&r2=318097&view=diff
==============================================================================
--- lld/trunk/test/ELF/mips-micro-plt.s (original)
+++ lld/trunk/test/ELF/mips-micro-plt.s Mon Nov 13 14:40:36 2017
@@ -6,10 +6,56 @@
 # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \
 # RUN:         -mattr=micromips %s -o %t-exe.o
 # RUN: ld.lld %t-exe.o %t.so -o %t.exe
-# RUN: llvm-readobj -mips-plt-got %t.exe | FileCheck %s
+# RUN: llvm-readobj -t -dt -mips-plt-got %t.exe | FileCheck %s
 
 # REQUIRES: mips
 
+# CHECK:      Symbols [
+# CHECK:        Symbol {
+# CHECK:          Name: foo
+# CHECK-NEXT:     Value: 0x20008
+# CHECK-NEXT:     Size:
+# CHECK-NEXT:     Binding: Local
+# CHECK-NEXT:     Type: None
+# CHECK-NEXT:     Other [
+# CHECK-NEXT:       STO_MIPS_MICROMIPS
+# CHECK-NEXT:       STV_HIDDEN
+# CHECK-NEXT:     ]
+# CHECK-NEXT:     Section: .text
+# CHECK-NEXT:   }
+# CHECK:        Symbol {
+# CHECK:          Name: __start
+# CHECK-NEXT:     Value: 0x20000
+# CHECK-NEXT:     Size:
+# CHECK-NEXT:     Binding: Global
+# CHECK-NEXT:     Type: None
+# CHECK-NEXT:     Other [
+# CHECK-NEXT:       STO_MIPS_MICROMIPS
+# CHECK-NEXT:     ]
+# CHECK-NEXT:     Section: .text
+# CHECK-NEXT:   }
+# CHECK:        Symbol {
+# CHECK:          Name: foo0
+# CHECK-NEXT:     Value: 0x0
+# CHECK-NEXT:     Size:
+# CHECK-NEXT:     Binding: Global
+# CHECK-NEXT:     Type: Function
+# CHECK-NEXT:     Other: 0
+# CHECK-NEXT:     Section: Undefined
+# CHECK-NEXT:   }
+# CHECK-NEXT: ]
+# CHECK:      DynamicSymbols [
+# CHECK:        Symbol {
+# CHECK:          Name: foo0
+# CHECK-NEXT:     Value: 0x0
+# CHECK-NEXT:     Size:
+# CHECK-NEXT:     Binding: Global
+# CHECK-NEXT:     Type: Function
+# CHECK-NEXT:     Other: 0
+# CHECK-NEXT:     Section: Undefined
+# CHECK-NEXT:   }
+# CHECK-NEXT: ]
+
 # CHECK:      Primary GOT {
 # CHECK:        Local entries [
 # CHECK-NEXT:     Entry {




More information about the llvm-commits mailing list