From ed0ab15170f0f8fc4269d58757378bc8726b56a1 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 25 Jan 2010 18:30:45 +0000 Subject: [PATCH] add symbol attribute support for the ELF .type directive. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94435 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/MC/MCDirectives.h | 32 +++++++++++++++++++------------- lib/MC/MCAsmStreamer.cpp | 24 +++++++++++++++++++++++- lib/MC/MCMachOStreamer.cpp | 6 ++++++ 3 files changed, 48 insertions(+), 14 deletions(-) diff --git a/include/llvm/MC/MCDirectives.h b/include/llvm/MC/MCDirectives.h index 57ce75db4f0..609a9a4a6df 100644 --- a/include/llvm/MC/MCDirectives.h +++ b/include/llvm/MC/MCDirectives.h @@ -20,19 +20,25 @@ enum MCSymbolAttr { MCSA_Invalid = 0, /// Not a valid directive. // Various directives in alphabetical order. - MCSA_Global, /// .globl - MCSA_Hidden, /// .hidden (ELF) - MCSA_IndirectSymbol, /// .indirect_symbol (MachO) - MCSA_Internal, /// .internal (ELF) - MCSA_LazyReference, /// .lazy_reference (MachO) - MCSA_Local, /// .local (ELF) - MCSA_NoDeadStrip, /// .no_dead_strip (MachO) - MCSA_PrivateExtern, /// .private_extern (MachO) - MCSA_Protected, /// .protected (ELF) - MCSA_Reference, /// .reference (MachO) - MCSA_Weak, /// .weak - MCSA_WeakDefinition, /// .weak_definition (MachO) - MCSA_WeakReference /// .weak_reference (MachO) + MCSA_ELF_TypeFunction, /// .type _foo, STT_FUNC # aka @function + MCSA_ELF_TypeIndFunction, /// .type _foo, STT_GNU_IFUNC + MCSA_ELF_TypeObject, /// .type _foo, STT_OBJECT # aka @object + MCSA_ELF_TypeTLS, /// .type _foo, STT_TLS # aka @tls_object + MCSA_ELF_TypeCommon, /// .type _foo, STT_COMMON # aka @common + MCSA_ELF_TypeNoType, /// .type _foo, STT_NOTYPE # aka @notype + MCSA_Global, /// .globl + MCSA_Hidden, /// .hidden (ELF) + MCSA_IndirectSymbol, /// .indirect_symbol (MachO) + MCSA_Internal, /// .internal (ELF) + MCSA_LazyReference, /// .lazy_reference (MachO) + MCSA_Local, /// .local (ELF) + MCSA_NoDeadStrip, /// .no_dead_strip (MachO) + MCSA_PrivateExtern, /// .private_extern (MachO) + MCSA_Protected, /// .protected (ELF) + MCSA_Reference, /// .reference (MachO) + MCSA_Weak, /// .weak + MCSA_WeakDefinition, /// .weak_definition (MachO) + MCSA_WeakReference /// .weak_reference (MachO) }; enum MCAssemblerFlag { diff --git a/lib/MC/MCAsmStreamer.cpp b/lib/MC/MCAsmStreamer.cpp index 6ce040efd6b..f577ad4b4b6 100644 --- a/lib/MC/MCAsmStreamer.cpp +++ b/lib/MC/MCAsmStreamer.cpp @@ -227,7 +227,29 @@ void MCAsmStreamer::EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) { switch (Attribute) { case MCSA_Invalid: assert(0 && "Invalid symbol attribute"); - case MCSA_Global: OS << MAI.getGlobalDirective(); break; // .globl + case MCSA_ELF_TypeFunction: /// .type _foo, STT_FUNC # aka @function + case MCSA_ELF_TypeIndFunction: /// .type _foo, STT_GNU_IFUNC + case MCSA_ELF_TypeObject: /// .type _foo, STT_OBJECT # aka @object + case MCSA_ELF_TypeTLS: /// .type _foo, STT_TLS # aka @tls_object + case MCSA_ELF_TypeCommon: /// .type _foo, STT_COMMON # aka @common + case MCSA_ELF_TypeNoType: /// .type _foo, STT_NOTYPE # aka @notype + assert(MAI.hasDotTypeDotSizeDirective() && "Symbol Attr not supported"); + OS << ".type " << *Symbol << ',' + << ((MAI.getCommentString()[0] != '@') ? '@' : '%'); + switch (Attribute) { + default: assert(0 && "Unknown ELF .type"); + case MCSA_ELF_TypeFunction: OS << "function"; break; + case MCSA_ELF_TypeIndFunction: OS << "gnu_indirect_function"; break; + case MCSA_ELF_TypeObject: OS << "object"; break; + case MCSA_ELF_TypeTLS: OS << "tls_object"; break; + case MCSA_ELF_TypeCommon: OS << "common"; break; + case MCSA_ELF_TypeNoType: OS << "no_type"; break; + } + EmitEOL(); + return; + case MCSA_Global: // .globl/.global + OS << MAI.getGlobalDirective(); + break; case MCSA_Hidden: OS << ".hidden "; break; case MCSA_IndirectSymbol: OS << ".indirect_symbol "; break; case MCSA_Internal: OS << ".internal "; break; diff --git a/lib/MC/MCMachOStreamer.cpp b/lib/MC/MCMachOStreamer.cpp index bd93f62a2f7..acfda32cdaa 100644 --- a/lib/MC/MCMachOStreamer.cpp +++ b/lib/MC/MCMachOStreamer.cpp @@ -223,6 +223,12 @@ void MCMachOStreamer::EmitSymbolAttribute(MCSymbol *Symbol, // defined. switch (Attribute) { case MCSA_Invalid: + case MCSA_ELF_TypeFunction: + case MCSA_ELF_TypeIndFunction: + case MCSA_ELF_TypeObject: + case MCSA_ELF_TypeTLS: + case MCSA_ELF_TypeCommon: + case MCSA_ELF_TypeNoType: case MCSA_IndirectSymbol: case MCSA_Hidden: case MCSA_Internal: