Index: lib/CodeGen/TargetLoweringObjectFileImpl.cpp =================================================================== --- lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -588,15 +588,18 @@ bool EmitUniqueSection = false; - // If we have -ffunction-sections or -fdata-sections then we should emit the - // global value to a uniqued section of the same name. - if (!(Flags & ELF::SHF_MERGE) && !Kind.isCommon()) { - if (Kind.isText()) - EmitUniqueSection = TM.getFunctionSections(); - else - EmitUniqueSection = TM.getDataSections(); + if (TM.getMCAsmInfo()->useIntegratedAssembler()) { + // If we are using the integrated assembler and we have -ffunction-sections + // or -fdata-sections, then we emit the global value into a uniqued section + // of the same name. + if (!(Flags & ELF::SHF_MERGE) && !Kind.isCommon()) { + if (Kind.isText()) + EmitUniqueSection = TM.getFunctionSections(); + else + EmitUniqueSection = TM.getDataSections(); + } + EmitUniqueSection |= GO->hasComdat(); } - EmitUniqueSection |= GO->hasComdat(); // A section can have at most one associated section. Put each global with // MD_associated in a unique section. Index: test/CodeGen/X86/explicit-elf-sections.ll =================================================================== --- test/CodeGen/X86/explicit-elf-sections.ll +++ test/CodeGen/X86/explicit-elf-sections.ll @@ -1,4 +1,5 @@ ; RUN: llc < %s -mtriple=x86_64-pc-linux -function-sections=1 -data-sections=1 | FileCheck %s -check-prefix=SECTIONS +; RUN: llc < %s -mtriple=x86_64-pc-linux -no-integrated-as -function-sections=1 -data-sections=1 | FileCheck %s -check-prefix=NIAS ; RUN: llc < %s -mtriple=x86_64-pc-linux -function-sections=0 -data-sections=0 | FileCheck %s -check-prefix=NSECTIONS define void @f() section "aaa" { ret void } @@ -63,3 +64,28 @@ ; SECTIONS: w: +; With -no-integrated-as, function and data sections are only created +; for implicit sections. +; +; NIAS: .section aaa,"ax",@progbits +; NIAS-NOT: {{\.section|\.text|\.data}} +; NIAS: f: +; NIAS-NOT: {{\.section|\.text|\.data}} +; NIAS: g: +; NIAS: .section .text.h,"ax",@progbits +; NIAS-NOT: {{\.section|\.text|\.data}} +; NIAS: h: +; NIAS: .section aaa,"ax",@progbits +; NIAS-NOT: {{\.section|\.text|\.data}} +; NIAS: i: +; NIAS-NOT: {{\.section|\.text|\.data}} +; NIAS: x: +; NIAS-NOT: {{\.section|\.text|\.data}} +; NIAS: y: +; NIAS: .section .data.z,"aw",@progbits +; NIAS-NOT: {{\.section|\.text|\.data}} +; NIAS: z: +; NIAS: .section aaa,"ax",@progbits +; NIAS-NOT: {{\.section|\.text|\.data}} +; NIAS: w: +