[PATCH] D21616: [IRObjectFile] Propagate .weak attribute correctly in symbols
Rafael EspĂndola via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 22 13:40:37 PDT 2016
Lgtm.
We should also add support for weak undefined, but that can be a followup
patch.
Cheers,
Rafael
On Jun 22, 2016 3:47 PM, "Davide Italiano" <dccitaliano at gmail.com> wrote:
> davide created this revision.
> davide added a reviewer: rafael.
> davide added a subscriber: llvm-commits.
>
> This should fix PR28256, see https://llvm.org/bugs/show_bug.cgi?id=28256
> for reference.
>
> http://reviews.llvm.org/D21616
>
> Files:
> lib/Object/IRObjectFile.cpp
> lib/Object/RecordStreamer.cpp
> lib/Object/RecordStreamer.h
> test/Object/X86/nm-bitcodeweak.test
>
> Index: test/Object/X86/nm-bitcodeweak.test
> ===================================================================
> --- test/Object/X86/nm-bitcodeweak.test
> +++ test/Object/X86/nm-bitcodeweak.test
> @@ -1,7 +1,7 @@
> ; RUN: llvm-as %s -o=%t1
> ; RUN: llvm-nm %t1 | FileCheck %s
>
> -; CHECK: T __libc_blah
> +; CHECK: W __libc_blah
>
> target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
> target triple = "x86_64-unknown-freebsd11.0"
> Index: lib/Object/RecordStreamer.h
> ===================================================================
> --- lib/Object/RecordStreamer.h
> +++ lib/Object/RecordStreamer.h
> @@ -15,12 +15,12 @@
> namespace llvm {
> class RecordStreamer : public MCStreamer {
> public:
> - enum State { NeverSeen, Global, Defined, DefinedGlobal, Used };
> + enum State { NeverSeen, Global, GlobalWeak, Defined, DefinedGlobal,
> Used };
>
> private:
> StringMap<State> Symbols;
> void markDefined(const MCSymbol &Symbol);
> - void markGlobal(const MCSymbol &Symbol);
> + void markGlobal(const MCSymbol &Symbol, MCSymbolAttr Attribute);
> void markUsed(const MCSymbol &Symbol);
> void visitUsedSymbol(const MCSymbol &Sym) override;
>
> Index: lib/Object/RecordStreamer.cpp
> ===================================================================
> --- lib/Object/RecordStreamer.cpp
> +++ lib/Object/RecordStreamer.cpp
> @@ -23,21 +23,26 @@
> case Used:
> S = Defined;
> break;
> + case GlobalWeak:
> + break;
> }
> }
>
> -void RecordStreamer::markGlobal(const MCSymbol &Symbol) {
> +void RecordStreamer::markGlobal(const MCSymbol &Symbol,
> + MCSymbolAttr Attribute) {
> State &S = Symbols[Symbol.getName()];
> switch (S) {
> case DefinedGlobal:
> case Defined:
> - S = DefinedGlobal;
> + S = (Attribute == MCSA_Weak) ? GlobalWeak : DefinedGlobal;
> break;
>
> case NeverSeen:
> case Global:
> case Used:
> - S = Global;
> + S = (Attribute == MCSA_Weak) ? GlobalWeak : Global;
> + break;
> + case GlobalWeak:
> break;
> }
> }
> @@ -48,6 +53,7 @@
> case DefinedGlobal:
> case Defined:
> case Global:
> + case GlobalWeak:
> break;
>
> case NeverSeen:
> @@ -85,7 +91,7 @@
> bool RecordStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
> MCSymbolAttr Attribute) {
> if (Attribute == MCSA_Global || Attribute == MCSA_Weak)
> - markGlobal(*Symbol);
> + markGlobal(*Symbol, Attribute);
> return true;
> }
>
> Index: lib/Object/IRObjectFile.cpp
> ===================================================================
> --- lib/Object/IRObjectFile.cpp
> +++ lib/Object/IRObjectFile.cpp
> @@ -116,6 +116,9 @@
> Res |= BasicSymbolRef::SF_Undefined;
> Res |= BasicSymbolRef::SF_Global;
> break;
> + case RecordStreamer::GlobalWeak:
> + Res |= BasicSymbolRef::SF_Weak;
> + Res |= BasicSymbolRef::SF_Global;
> }
> AsmUndefinedRefs(Key, BasicSymbolRef::Flags(Res));
> }
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160622/4416724a/attachment.html>
More information about the llvm-commits
mailing list