[llvm-branch-commits] [llvm] 553d4d0 - [MC] Report locations for .symver errors

Fangrui Song via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sun Dec 20 21:09:00 PST 2020


Author: Fangrui Song
Date: 2020-12-20T21:04:12-08:00
New Revision: 553d4d08d2bee53d2cc19ea5160a0dfbffe12fa9

URL: https://github.com/llvm/llvm-project/commit/553d4d08d2bee53d2cc19ea5160a0dfbffe12fa9
DIFF: https://github.com/llvm/llvm-project/commit/553d4d08d2bee53d2cc19ea5160a0dfbffe12fa9.diff

LOG: [MC] Report locations for .symver errors

Added: 
    llvm/test/MC/ELF/symver-err.s

Modified: 
    llvm/include/llvm/MC/MCAssembler.h
    llvm/lib/MC/ELFObjectWriter.cpp
    llvm/lib/MC/MCELFStreamer.cpp

Removed: 
    llvm/test/MC/ELF/invalid-symver.s
    llvm/test/MC/ELF/multiple-different-symver.s
    llvm/test/MC/ELF/multiple-equiv-symver.s


################################################################################
diff  --git a/llvm/include/llvm/MC/MCAssembler.h b/llvm/include/llvm/MC/MCAssembler.h
index 15c0be436fd8..1b76559d33b3 100644
--- a/llvm/include/llvm/MC/MCAssembler.h
+++ b/llvm/include/llvm/MC/MCAssembler.h
@@ -211,7 +211,12 @@ class MCAssembler {
   handleFixup(const MCAsmLayout &Layout, MCFragment &F, const MCFixup &Fixup);
 
 public:
-  std::vector<std::pair<StringRef, const MCSymbol *>> Symvers;
+  struct Symver {
+    StringRef Name;
+    const MCSymbol *Sym;
+    SMLoc Loc;
+  };
+  std::vector<Symver> Symvers;
 
   /// Construct a new assembler instance.
   //

diff  --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp
index 9cf29ba0a232..d5da8deab0f0 100644
--- a/llvm/lib/MC/ELFObjectWriter.cpp
+++ b/llvm/lib/MC/ELFObjectWriter.cpp
@@ -1258,9 +1258,9 @@ void ELFObjectWriter::executePostLayoutBinding(MCAssembler &Asm,
                                                const MCAsmLayout &Layout) {
   // The presence of symbol versions causes undefined symbols and
   // versions declared with @@@ to be renamed.
-  for (const std::pair<StringRef, const MCSymbol *> &P : Asm.Symvers) {
-    StringRef AliasName = P.first;
-    const auto &Symbol = cast<MCSymbolELF>(*P.second);
+  for (const MCAssembler::Symver &S : Asm.Symvers) {
+    StringRef AliasName = S.Name;
+    const auto &Symbol = cast<MCSymbolELF>(*S.Sym);
     size_t Pos = AliasName.find('@');
     assert(Pos != StringRef::npos);
 
@@ -1286,18 +1286,16 @@ void ELFObjectWriter::executePostLayoutBinding(MCAssembler &Asm,
     if (!Symbol.isUndefined() && !Rest.startswith("@@@"))
       continue;
 
-    // FIXME: Get source locations for these errors or diagnose them earlier.
     if (Symbol.isUndefined() && Rest.startswith("@@") &&
         !Rest.startswith("@@@")) {
-      Asm.getContext().reportError(SMLoc(), "versioned symbol " + AliasName +
-                                                " must be defined");
+      Asm.getContext().reportError(S.Loc, "default version symbol " +
+                                              AliasName + " must be defined");
       continue;
     }
 
     if (Renames.count(&Symbol) && Renames[&Symbol] != Alias) {
-      Asm.getContext().reportError(
-          SMLoc(), llvm::Twine("multiple symbol versions defined for ") +
-                       Symbol.getName());
+      Asm.getContext().reportError(S.Loc, Twine("multiple versions for ") +
+                                              Symbol.getName());
       continue;
     }
 

diff  --git a/llvm/lib/MC/MCELFStreamer.cpp b/llvm/lib/MC/MCELFStreamer.cpp
index acd8af13c6aa..17beca1c3556 100644
--- a/llvm/lib/MC/MCELFStreamer.cpp
+++ b/llvm/lib/MC/MCELFStreamer.cpp
@@ -342,7 +342,8 @@ void MCELFStreamer::emitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
 
 void MCELFStreamer::emitELFSymverDirective(StringRef AliasName,
                                            const MCSymbol *Aliasee) {
-  getAssembler().Symvers.push_back({AliasName, Aliasee});
+  getAssembler().Symvers.push_back(
+      MCAssembler::Symver{AliasName, Aliasee, getStartTokLoc()});
 }
 
 void MCELFStreamer::emitLocalCommonSymbol(MCSymbol *S, uint64_t Size,

diff  --git a/llvm/test/MC/ELF/invalid-symver.s b/llvm/test/MC/ELF/invalid-symver.s
deleted file mode 100644
index d9f97b102b57..000000000000
--- a/llvm/test/MC/ELF/invalid-symver.s
+++ /dev/null
@@ -1,7 +0,0 @@
-// RUN: not llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o %t 2> %t.out
-// RUN: FileCheck --input-file=%t.out %s
-
-// CHECK: error: versioned symbol foo@@bar must be defined
-
-        .symver undefined, foo@@bar
-        .long undefined

diff  --git a/llvm/test/MC/ELF/multiple-
diff erent-symver.s b/llvm/test/MC/ELF/multiple-
diff erent-symver.s
deleted file mode 100644
index c34626c08173..000000000000
--- a/llvm/test/MC/ELF/multiple-
diff erent-symver.s
+++ /dev/null
@@ -1,6 +0,0 @@
-// RUN: not llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o %t 2>&1 | FileCheck %s
-
-// CHECK: error: multiple symbol versions defined for foo
-
-.symver foo, foo at 1
-.symver foo, foo at 2

diff  --git a/llvm/test/MC/ELF/multiple-equiv-symver.s b/llvm/test/MC/ELF/multiple-equiv-symver.s
deleted file mode 100644
index 0ab48f0992d0..000000000000
--- a/llvm/test/MC/ELF/multiple-equiv-symver.s
+++ /dev/null
@@ -1,6 +0,0 @@
-// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - 2>&1 | FileCheck %s
-
-// CHECK-NOT: Multiple symbol versions defined for foo
-
-.symver foo, foo at 1
-.symver foo, foo at 1

diff  --git a/llvm/test/MC/ELF/symver-err.s b/llvm/test/MC/ELF/symver-err.s
new file mode 100644
index 000000000000..66640bedba62
--- /dev/null
+++ b/llvm/test/MC/ELF/symver-err.s
@@ -0,0 +1,12 @@
+# RUN: not llvm-mc -filetype=obj -triple=x86_64 %s -o /dev/null 2>&1 | FileCheck %s --implicit-check-not=error:
+
+# CHECK: {{.*}}.s:[[#@LINE+2]]:1: error: multiple versions for multi
+.symver multi, multi at 1
+.symver multi, multi at 2
+
+.symver equiv, equiv at 1
+.symver equiv, equiv at 1
+
+# CHECK: {{.*}}.s:[[#@LINE+1]]:1: error: default version symbol undefined@@v1 must be defined
+.symver undefined_2, undefined@@v1
+.long undefined_2


        


More information about the llvm-branch-commits mailing list