[llvm] r327930 - Object: Fix handling of @@@ in .symver directive
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 19 17:45:03 PDT 2018
Author: vitalybuka
Date: Mon Mar 19 17:45:03 2018
New Revision: 327930
URL: http://llvm.org/viewvc/llvm-project?rev=327930&view=rev
Log:
Object: Fix handling of @@@ in .symver directive
Summary:
name@@@nodename is going to be replaced with name@@nodename if symbols is
defined in the assembled file, or name at nodename if undefined.
https://sourceware.org/binutils/docs/as/Symver.html
Fixes PR36623
Reviewers: pcc, espindola
Subscribers: mehdi_amini, hiraditya
Differential Revision: https://reviews.llvm.org/D44274
Added:
llvm/trunk/test/LTO/X86/symver-asm3.ll
Modified:
llvm/trunk/lib/Object/RecordStreamer.cpp
Modified: llvm/trunk/lib/Object/RecordStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/RecordStreamer.cpp?rev=327930&r1=327929&r2=327930&view=diff
==============================================================================
--- llvm/trunk/lib/Object/RecordStreamer.cpp (original)
+++ llvm/trunk/lib/Object/RecordStreamer.cpp Mon Mar 19 17:45:03 2018
@@ -149,6 +149,7 @@ void RecordStreamer::flushSymverDirectiv
for (auto &Symver : SymverAliasMap) {
const MCSymbol *Aliasee = Symver.first;
MCSymbolAttr Attr = MCSA_Invalid;
+ bool IsDefined = false;
// First check if the aliasee binding was recorded in the asm.
RecordStreamer::State state = getSymbolState(Aliasee);
@@ -165,26 +166,52 @@ void RecordStreamer::flushSymverDirectiv
break;
}
- // If we don't have a symbol attribute from assembly, then check if
- // the aliasee was defined in the IR.
- if (Attr == MCSA_Invalid) {
- const auto *GV = M.getNamedValue(Aliasee->getName());
+ switch (state) {
+ case RecordStreamer::Defined:
+ case RecordStreamer::DefinedGlobal:
+ case RecordStreamer::DefinedWeak:
+ IsDefined = true;
+ break;
+ case RecordStreamer::NeverSeen:
+ case RecordStreamer::Global:
+ case RecordStreamer::Used:
+ case RecordStreamer::UndefinedWeak:
+ break;
+ }
+
+ if (Attr == MCSA_Invalid || !IsDefined) {
+ const GlobalValue *GV = M.getNamedValue(Aliasee->getName());
if (!GV) {
auto MI = MangledNameMap.find(Aliasee->getName());
if (MI != MangledNameMap.end())
GV = MI->second;
}
if (GV) {
- if (GV->hasExternalLinkage())
- Attr = MCSA_Global;
- else if (GV->hasLocalLinkage())
- Attr = MCSA_Local;
- else if (GV->isWeakForLinker())
- Attr = MCSA_Weak;
+ // If we don't have a symbol attribute from assembly, then check if
+ // the aliasee was defined in the IR.
+ if (Attr == MCSA_Invalid) {
+ if (GV->hasExternalLinkage())
+ Attr = MCSA_Global;
+ else if (GV->hasLocalLinkage())
+ Attr = MCSA_Local;
+ else if (GV->isWeakForLinker())
+ Attr = MCSA_Weak;
+ }
+ IsDefined = IsDefined || !GV->isDeclarationForLinker();
}
}
+
// Set the detected binding on each alias with this aliasee.
for (auto AliasName : Symver.second) {
+ std::pair<StringRef, StringRef> Split = AliasName.split("@@@");
+ SmallString<128> NewName;
+ if (!Split.second.empty() && !Split.second.startswith("@")) {
+ // Special processing for "@@@" according
+ // https://sourceware.org/binutils/docs/as/Symver.html
+ const char *Separator = IsDefined ? "@@" : "@";
+ AliasName =
+ (Split.first + Separator + Split.second).toStringRef(NewName);
+ }
MCSymbol *Alias = getContext().getOrCreateSymbol(AliasName);
// TODO: Handle "@@@". Depending on SymbolAttribute value it needs to be
// converted into @ or @@.
Added: llvm/trunk/test/LTO/X86/symver-asm3.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LTO/X86/symver-asm3.ll?rev=327930&view=auto
==============================================================================
--- llvm/trunk/test/LTO/X86/symver-asm3.ll (added)
+++ llvm/trunk/test/LTO/X86/symver-asm3.ll Mon Mar 19 17:45:03 2018
@@ -0,0 +1,40 @@
+; Test special handling of @@@.
+
+; RUN: llvm-as < %s >%t1
+; RUN: llvm-nm %t1 | FileCheck %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+module asm "foo1:"
+; CHECK-DAG: t foo1
+
+module asm ".symver foo1, foo@@@VER1"
+; CHECK-DAG: t foo@@VER1
+
+module asm ".symver foo2, foo@@@VER2"
+; CHECK-DAG: U foo2
+; CHECK-DAG: t foo at VER2
+
+module asm ".symver foo3, foo@@@VER3"
+; CHECK-DAG: t foo@@VER3
+
+module asm ".symver foo4, foo@@@VER4"
+; CHECK-DAG: T foo@@VER4
+
+module asm ".symver foo5, foo@@@VER5"
+; CHECK-DAG: T foo at VER5
+
+module asm "foo3:"
+; CHECK-DAG: t foo3
+
+module asm ".local foo1"
+module asm ".local foo3"
+
+define void @foo4() {
+; CHECK-DAG: T foo4
+ ret void
+}
+
+declare void @foo5()
+; CHECK-DAG: U foo5
More information about the llvm-commits
mailing list