Skip to content

Commit 8ad7399

Browse files
committedOct 15, 2015
[MachO] Stop generating *coal* sections.
Recommit r250342: move coal-sections-powerpc.s to subdirectory for powerpc. Some background on why we don't have to use *coal* sections anymore: Long ago when C++ was new and "weak" had not been standardized, an attempt was made in cctools to support C++ inlines that can be coalesced by putting them into their own section (TEXT/textcoal_nt instead of TEXT/text). The current macho linker supports the weak-def bit on any symbol to allow it to be coalesced, but the compiler still puts weak-def functions/data into alternate section names, which the linker must map back to the base section name. This patch makes changes that are necessary to prevent the compiler from using the "coal" sections and have it use the non-coal sections instead when the target architecture is not powerpc: TEXT/textcoal_nt instead use TEXT/text TEXT/const_coal instead use TEXT/const DATA/datacoal_nt instead use DATA/data If the target is powerpc, we continue to use the *coal* sections since anyone targeting powerpc is probably using an old linker that doesn't have support for the weak-def bits. Also, have the assembler issue a warning if it encounters a *coal* section in the assembly file and inform the users to use the non-coal sections instead. rdar://problem/14265330 Differential Revision: http://reviews.llvm.org/D13188 llvm-svn: 250370
1 parent 1ac9bfb commit 8ad7399

File tree

8 files changed

+199
-17
lines changed

8 files changed

+199
-17
lines changed
 

‎llvm/lib/MC/MCObjectFileInfo.cpp

+28-13
Original file line numberDiff line numberDiff line change
@@ -114,22 +114,37 @@ void MCObjectFileInfo::initMachOMCObjectFileInfo(Triple T) {
114114
= Ctx->getMachOSection("__TEXT", "__const", 0,
115115
SectionKind::getReadOnly());
116116

117-
TextCoalSection
118-
= Ctx->getMachOSection("__TEXT", "__textcoal_nt",
119-
MachO::S_COALESCED |
120-
MachO::S_ATTR_PURE_INSTRUCTIONS,
121-
SectionKind::getText());
122-
ConstTextCoalSection
123-
= Ctx->getMachOSection("__TEXT", "__const_coal",
124-
MachO::S_COALESCED,
125-
SectionKind::getReadOnly());
117+
// If the target is not powerpc, map the coal sections to the non-coal
118+
// sections.
119+
//
120+
// "__TEXT/__textcoal_nt" => section "__TEXT/__text"
121+
// "__TEXT/__const_coal" => section "__TEXT/__const"
122+
// "__DATA/__datacoal_nt" => section "__DATA/__data"
123+
Triple::ArchType ArchTy = T.getArch();
124+
125+
if (ArchTy == Triple::ppc || ArchTy == Triple::ppc64) {
126+
TextCoalSection
127+
= Ctx->getMachOSection("__TEXT", "__textcoal_nt",
128+
MachO::S_COALESCED |
129+
MachO::S_ATTR_PURE_INSTRUCTIONS,
130+
SectionKind::getText());
131+
ConstTextCoalSection
132+
= Ctx->getMachOSection("__TEXT", "__const_coal",
133+
MachO::S_COALESCED,
134+
SectionKind::getReadOnly());
135+
DataCoalSection
136+
= Ctx->getMachOSection("__DATA","__datacoal_nt",
137+
MachO::S_COALESCED,
138+
SectionKind::getDataRel());
139+
} else {
140+
TextCoalSection = TextSection;
141+
ConstTextCoalSection = ReadOnlySection;
142+
DataCoalSection = DataSection;
143+
}
144+
126145
ConstDataSection // .const_data
127146
= Ctx->getMachOSection("__DATA", "__const", 0,
128147
SectionKind::getReadOnlyWithRel());
129-
DataCoalSection
130-
= Ctx->getMachOSection("__DATA","__datacoal_nt",
131-
MachO::S_COALESCED,
132-
SectionKind::getDataRel());
133148
DataCommonSection
134149
= Ctx->getMachOSection("__DATA","__common",
135150
MachO::S_ZEROFILL,

‎llvm/lib/MC/MCParser/DarwinAsmParser.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
#include "llvm/MC/MCParser/MCAsmParserExtension.h"
1111
#include "llvm/ADT/StringRef.h"
1212
#include "llvm/ADT/StringSwitch.h"
13+
#include "llvm/ADT/Triple.h"
1314
#include "llvm/ADT/Twine.h"
1415
#include "llvm/MC/MCContext.h"
16+
#include "llvm/MC/MCObjectFileInfo.h"
1517
#include "llvm/MC/MCParser/MCAsmLexer.h"
1618
#include "llvm/MC/MCParser/MCAsmParser.h"
1719
#include "llvm/MC/MCSectionMachO.h"
@@ -579,6 +581,29 @@ bool DarwinAsmParser::parseDirectiveSection(StringRef, SMLoc) {
579581
if (!ErrorStr.empty())
580582
return Error(Loc, ErrorStr.c_str());
581583

584+
// Issue a warning if the target is not powerpc and Section is a *coal* section.
585+
Triple TT = getParser().getContext().getObjectFileInfo()->getTargetTriple();
586+
Triple::ArchType ArchTy = TT.getArch();
587+
588+
if (ArchTy != Triple::ppc && ArchTy != Triple::ppc64) {
589+
StringRef NonCoalSection = StringSwitch<StringRef>(Section)
590+
.Case("__textcoal_nt", "__text")
591+
.Case("__const_coal", "__const")
592+
.Case("__datacoal_nt", "__data")
593+
.Default(Section);
594+
595+
if (!Section.equals(NonCoalSection)) {
596+
StringRef SectionVal(Loc.getPointer());
597+
size_t B = SectionVal.find(',') + 1, E = SectionVal.find(',', B);
598+
SMLoc BLoc = SMLoc::getFromPointer(SectionVal.data() + B);
599+
SMLoc ELoc = SMLoc::getFromPointer(SectionVal.data() + E);
600+
getParser().Warning(Loc, "section \"" + Section + "\" is deprecated",
601+
SMRange(BLoc, ELoc));
602+
getParser().Note(Loc, "change section name to \"" + NonCoalSection +
603+
"\"", SMRange(BLoc, ELoc));
604+
}
605+
}
606+
582607
// FIXME: Arch specific.
583608
bool isText = Segment == "__TEXT"; // FIXME: Hack.
584609
getStreamer().SwitchSection(getContext().getMachOSection(
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
; RUN: llc < %s -mtriple powerpc-apple-darwin8 -march=ppc32 | FileCheck %s
2+
3+
; Check that *coal* sections are emitted.
4+
5+
; CHECK: .section __TEXT,__textcoal_nt,coalesced,pure_instructions
6+
; CHECK: .section __TEXT,__textcoal_nt,coalesced,pure_instructions
7+
; CHECK-NEXT: .globl _foo
8+
9+
; CHECK: .section __TEXT,__const_coal,coalesced
10+
; CHECK-NEXT: .globl _a
11+
12+
; CHECK: .section __DATA,__datacoal_nt,coalesced
13+
; CHECK-NEXT: .globl _b
14+
15+
@a = weak_odr constant [4 x i32] [i32 1, i32 2, i32 3, i32 4], align 16
16+
@b = weak global i32 5, align 4
17+
@g = common global i32* null, align 8
18+
19+
; Function Attrs: nounwind ssp uwtable
20+
define weak i32* @foo() {
21+
entry:
22+
store i32* getelementptr inbounds ([4 x i32], [4 x i32]* @a, i64 0, i64 0), i32** @g, align 8
23+
ret i32* @b
24+
}
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
; RUN: llc < %s -mtriple x86_64-apple-darwin | FileCheck %s
2+
3+
; Check that *coal* sections are not emitted.
4+
5+
; CHECK: .section __TEXT,__text,regular,pure_instructions{{$}}
6+
; CHECK-NEXT: .globl _foo
7+
8+
; CHECK: .section __TEXT,__const{{$}}
9+
; CHECK-NEXT: .globl _a
10+
11+
; CHECK: .section __DATA,__data{{$}}
12+
; CHECK-NEXT: .globl _b
13+
14+
@a = weak_odr constant [4 x i32] [i32 1, i32 2, i32 3, i32 4], align 16
15+
@b = weak global i32 5, align 4
16+
@g = common global i32* null, align 8
17+
18+
; Function Attrs: nounwind ssp uwtable
19+
define weak i32* @foo() {
20+
entry:
21+
store i32* getelementptr inbounds ([4 x i32], [4 x i32]* @a, i64 0, i64 0), i32** @g, align 8
22+
ret i32* @b
23+
}

‎llvm/test/CodeGen/X86/global-sections.ll

+3-4
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ bb7:
117117

118118
; TODO: linux drops this into .rodata, we drop it into ".gnu.linkonce.r.G2"
119119

120-
; DARWIN: .section __TEXT,__const_coal,coalesced
120+
; DARWIN: .section __TEXT,__const{{$}}
121121
; DARWIN: _G2:
122122
; DARWIN: .long 42
123123

@@ -176,7 +176,6 @@ bb7:
176176
; LINUX: .weak "foo bar"
177177
; LINUX: "foo bar":
178178

179-
; DARWIN: .section __DATA,__datacoal_nt,coalesced
180179
; DARWIN: .globl "_foo bar"
181180
; DARWIN: .weak_definition "_foo bar"
182181
; DARWIN: "_foo bar":
@@ -190,7 +189,7 @@ bb7:
190189
; LINUX: .byte 1
191190
; LINUX: .size G6, 1
192191

193-
; DARWIN: .section __TEXT,__const_coal,coalesced
192+
; DARWIN: .section __TEXT,__const{{$}}
194193
; DARWIN: .globl _G6
195194
; DARWIN: .weak_definition _G6
196195
; DARWIN:_G6:
@@ -239,7 +238,7 @@ bb7:
239238
@G10 = weak global [100 x i32] zeroinitializer, align 32 ; <[100 x i32]*> [#uses=0]
240239

241240

242-
; DARWIN: .section __DATA,__datacoal_nt,coalesced
241+
; DARWIN: .section __DATA,__data{{$}}
243242
; DARWIN: .globl _G10
244243
; DARWIN: .weak_definition _G10
245244
; DARWIN: .align 5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// RUN: llvm-mc -triple powerpc-apple-darwin8 -arch=ppc32 -filetype=obj %s -o - | llvm-readobj -sections | FileCheck %s
2+
3+
// CHECK: Section {
4+
// CHECK-NEXT: Index: 0
5+
6+
// CHECK: Section {
7+
// CHECK-NEXT: Index: 1
8+
// CHECK-NEXT: Name: __textcoal_nt (
9+
10+
// CHECK: Section {
11+
// CHECK-NEXT: Index: 2
12+
13+
// CHECK: Section {
14+
// CHECK-NEXT: Index: 3
15+
// CHECK-NEXT: Name: __const_coal (
16+
17+
// CHECK: Section {
18+
// CHECK-NEXT: Index: 4
19+
// CHECK-NEXT: Name: __datacoal_nt (
20+
21+
.section __TEXT,__text,regular,pure_instructions
22+
.machine ppc
23+
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
24+
.section __TEXT,__symbol_stub1,symbol_stubs,pure_instructions,16
25+
.section __TEXT,__text,regular,pure_instructions
26+
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
27+
.globl _foo
28+
.weak_definition _foo
29+
.align 4
30+
_foo:
31+
blr
32+
33+
.subsections_via_symbols
34+
.section __TEXT,__const_coal,coalesced
35+
.globl _a ; @a
36+
.weak_definition _a
37+
.align 4
38+
_a:
39+
.long 1 ; 0x1
40+
41+
.section __DATA,__datacoal_nt,coalesced
42+
.globl _b ; @b
43+
.weak_definition _b
44+
.align 2
45+
_b:
46+
.long 5 ; 0x5
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
if not 'PowerPC' in config.root.targets:
2+
config.unsupported = True
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// RUN: llvm-mc -triple x86_64-apple-darwin -filetype=obj %s -o - 2>%t.err | llvm-readobj -sections | FileCheck %s
2+
// RUN: FileCheck --check-prefix=WARNING < %t.err %s
3+
4+
// CHECK: Section {
5+
// CHECK-NEXT: Index: 0
6+
// CHECK-NEXT: Name: __text (
7+
8+
// CHECK: Section {
9+
// CHECK-NEXT: Index: 1
10+
// CHECK-NEXT: Name: __textcoal_nt (
11+
12+
// CHECK: Section {
13+
// CHECK-NEXT: Index: 2
14+
// CHECK-NEXT: Name: __const_coal (
15+
16+
// CHECK: Section {
17+
// CHECK-NEXT: Index: 3
18+
// CHECK-NEXT: Name: __datacoal_nt (
19+
20+
// WARNING: warning: section "__textcoal_nt" is deprecated
21+
// WARNING: note: change section name to "__text"
22+
// WARNING: warning: section "__const_coal" is deprecated
23+
// WARNING: note: change section name to "__const"
24+
// WARNING: warning: section "__datacoal_nt" is deprecated
25+
// WARNING: note: change section name to "__data"
26+
27+
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
28+
.globl _foo
29+
.weak_definition _foo
30+
.align 4, 0x90
31+
_foo:
32+
retq
33+
34+
.section __TEXT,__const_coal,coalesced
35+
.globl _a ## @a
36+
.weak_definition _a
37+
.align 4
38+
_a:
39+
.long 1 ## 0x1
40+
41+
.section __DATA,__datacoal_nt,coalesced
42+
.globl _b ## @b
43+
.weak_definition _b
44+
.align 2
45+
_b:
46+
.long 5 ## 0x5
47+
48+
.subsections_via_symbols

0 commit comments

Comments
 (0)
Please sign in to comment.