Index: lib/CodeGen/TargetLoweringObjectFileImpl.cpp =================================================================== --- lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -593,6 +593,10 @@ if (AssociatedSymbol) { UniqueID = NextUniqueID++; Flags |= ELF::SHF_LINK_ORDER; + } else if(F && TM.getFunctionSections()){ + // Also, if -ffunction-sections is used and the global is a function, then + // emit a unique section. + UniqueID = NextUniqueID++; } MCSectionELF *Section = getContext().getELFSection( Index: test/CodeGen/X86/explicit-function-sections.ll =================================================================== --- /dev/null +++ test/CodeGen/X86/explicit-function-sections.ll @@ -0,0 +1,24 @@ +; RUN: llc < %s -mtriple=x86_64-pc-linux -function-sections | FileCheck %s -check-prefix=FSECTIONS +; RUN: llc < %s -mtriple=x86_64-pc-linux | FileCheck %s -check-prefix=NOFSECTIONS + +define void @f() section "special_section" { + ret void +} +define void @g() section "special_section" { + ret void +} + +; NOFSECTIONS: .section special_section,"ax",@progbits +; NOFSECTIONS-NOT: section +; NOFSECTIONS: f: +; NOFSECTIONS-NOT: section +; NOFSECTIONS: g: + +; FSECTIONS: .section special_section,"ax",@progbits +; FSECTIONS-NOT: section +; FSECTIONS: f: +; FSECTIONS: .section special_section,"ax",@progbits +; FSECTIONS-NOT: section +; FSECTIONS: g: + +