Skip to content

Commit 449711c

Browse files
committed
Stop producing .data.rel sections.
If a section is rw, it is irrelevant if the dynamic linker will write to it or not. It looks like llvm implemented this because gcc was doing it. It looks like gcc implemented this in the hope that it would put all the relocated items close together and speed up the dynamic linker. There are two problem with this: * It doesn't work. Both bfd and gold will map .data.rel to .data and concatenate the input sections in the order they are seen. * If we want a feature like that, it can be implemented directly in the linker since it knowns where the dynamic relocations are. llvm-svn: 253436
1 parent e113b5e commit 449711c

24 files changed

+93
-134
lines changed

llvm/include/llvm/MC/MCObjectFileInfo.h

-2
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ class MCObjectFileInfo {
149149
MCSection *EHFrameSection;
150150

151151
// ELF specific sections.
152-
MCSection *DataRelSection;
153152
MCSection *DataRelROSection;
154153
MCSection *MergeableConst4Section;
155154
MCSection *MergeableConst8Section;
@@ -276,7 +275,6 @@ class MCObjectFileInfo {
276275
MCSection *getFaultMapSection() const { return FaultMapSection; }
277276

278277
// ELF specific sections.
279-
MCSection *getDataRelSection() const { return DataRelSection; }
280278
MCSection *getDataRelROSection() const { return DataRelROSection; }
281279
const MCSection *getMergeableConst4Section() const {
282280
return MergeableConst4Section;

llvm/include/llvm/MC/SectionKind.h

+5-17
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,8 @@ class SectionKind {
9999
/// marked 'constant'.
100100
Common,
101101

102-
/// DataRel - This is the most general form of data that is written
103-
/// to by the program, it can have random relocations to arbitrary
104-
/// globals.
105-
DataRel,
106-
107-
/// DataNoRel - This is writeable data that has a non-zero
108-
/// initializer, but whose initializer is known to have no
109-
/// relocations.
110-
DataNoRel,
102+
/// This is writeable data that has a non-zero initializer.
103+
Data,
111104

112105
/// ReadOnlyWithRel - These are global variables that are never
113106
/// written to by the program, but that have relocations, so they
@@ -155,7 +148,7 @@ class SectionKind {
155148
bool isThreadData() const { return K == ThreadData; }
156149

157150
bool isGlobalWriteableData() const {
158-
return isBSS() || isCommon() || isDataRel() || isReadOnlyWithRel();
151+
return isBSS() || isCommon() || isData() || isReadOnlyWithRel();
159152
}
160153

161154
bool isBSS() const { return K == BSS || K == BSSLocal || K == BSSExtern; }
@@ -164,11 +157,7 @@ class SectionKind {
164157

165158
bool isCommon() const { return K == Common; }
166159

167-
bool isDataRel() const {
168-
return K == DataRel || K == DataNoRel;
169-
}
170-
171-
bool isDataNoRel() const { return K == DataNoRel; }
160+
bool isData() const { return K == Data; }
172161

173162
bool isReadOnlyWithRel() const {
174163
return K == ReadOnlyWithRel;
@@ -202,8 +191,7 @@ class SectionKind {
202191
static SectionKind getBSSLocal() { return get(BSSLocal); }
203192
static SectionKind getBSSExtern() { return get(BSSExtern); }
204193
static SectionKind getCommon() { return get(Common); }
205-
static SectionKind getDataRel() { return get(DataRel); }
206-
static SectionKind getDataNoRel() { return get(DataNoRel); }
194+
static SectionKind getData() { return get(Data); }
207195
static SectionKind getReadOnlyWithRel() { return get(ReadOnlyWithRel); }
208196
};
209197

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

+2-7
Original file line numberDiff line numberDiff line change
@@ -355,12 +355,7 @@ static MCSymbol *getOrCreateEmuTLSInitSym(MCSymbol *GVSym, MCContext &C) {
355355
void AsmPrinter::EmitEmulatedTLSControlVariable(const GlobalVariable *GV,
356356
MCSymbol *EmittedSym,
357357
bool AllZeroInitValue) {
358-
// If there is init value, use .data.rel.local section;
359-
// otherwise use the .data section.
360-
MCSection *TLSVarSection =
361-
const_cast<MCSection *>((GV->hasInitializer() && !AllZeroInitValue)
362-
? getObjFileLowering().getDataRelSection()
363-
: getObjFileLowering().getDataSection());
358+
MCSection *TLSVarSection = getObjFileLowering().getDataSection();
364359
OutStreamer->SwitchSection(TLSVarSection);
365360
MCSymbol *GVSym = getSymbol(GV);
366361
EmitLinkage(GV, EmittedSym); // same linkage as GV
@@ -1139,7 +1134,7 @@ bool AsmPrinter::doFinalization(Module &M) {
11391134
// Output stubs for external and common global variables.
11401135
MachineModuleInfoELF::SymbolListTy Stubs = MMIELF.GetGVStubList();
11411136
if (!Stubs.empty()) {
1142-
OutStreamer->SwitchSection(TLOF.getDataRelSection());
1137+
OutStreamer->SwitchSection(TLOF.getDataSection());
11431138
const DataLayout &DL = M.getDataLayout();
11441139

11451140
for (const auto &Stub : Stubs) {

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,8 @@ static StringRef getSectionPrefixForGlobal(SectionKind Kind) {
233233
return ".tdata";
234234
if (Kind.isThreadBSS())
235235
return ".tbss";
236-
if (Kind.isDataNoRel())
236+
if (Kind.isData())
237237
return ".data";
238-
if (Kind.isDataRel())
239-
return ".data.rel";
240238
assert(Kind.isReadOnlyWithRel() && "Unknown section kind");
241239
return ".data.rel.ro";
242240
}
@@ -502,7 +500,7 @@ emitModuleFlags(MCStreamer &Streamer,
502500

503501
// Get the section.
504502
MCSectionMachO *S = getContext().getMachOSection(
505-
Segment, Section, TAA, StubSize, SectionKind::getDataNoRel());
503+
Segment, Section, TAA, StubSize, SectionKind::getData());
506504
Streamer.SwitchSection(S);
507505
Streamer.EmitLabel(getContext().
508506
getOrCreateSymbol(StringRef("L_OBJC_IMAGE_INFO")));
@@ -635,7 +633,7 @@ MCSection *TargetLoweringObjectFileMachO::getSectionForConstant(
635633
const DataLayout &DL, SectionKind Kind, const Constant *C) const {
636634
// If this constant requires a relocation, we have to put it in the data
637635
// segment, not in the text segment.
638-
if (Kind.isDataRel() || Kind.isReadOnlyWithRel())
636+
if (Kind.isData() || Kind.isReadOnlyWithRel())
639637
return ConstDataSection;
640638

641639
if (Kind.isMergeableConst4())

llvm/lib/MC/MCObjectFileInfo.cpp

+29-40
Original file line numberDiff line numberDiff line change
@@ -76,31 +76,29 @@ void MCObjectFileInfo::initMachOMCObjectFileInfo(Triple T) {
7676
MachO::S_ATTR_PURE_INSTRUCTIONS,
7777
SectionKind::getText());
7878
DataSection // .data
79-
= Ctx->getMachOSection("__DATA", "__data", 0,
80-
SectionKind::getDataRel());
79+
= Ctx->getMachOSection("__DATA", "__data", 0, SectionKind::getData());
8180

8281
// BSSSection might not be expected initialized on msvc.
8382
BSSSection = nullptr;
8483

8584
TLSDataSection // .tdata
86-
= Ctx->getMachOSection("__DATA", "__thread_data",
87-
MachO::S_THREAD_LOCAL_REGULAR,
88-
SectionKind::getDataRel());
85+
= Ctx->getMachOSection("__DATA", "__thread_data",
86+
MachO::S_THREAD_LOCAL_REGULAR,
87+
SectionKind::getData());
8988
TLSBSSSection // .tbss
9089
= Ctx->getMachOSection("__DATA", "__thread_bss",
9190
MachO::S_THREAD_LOCAL_ZEROFILL,
9291
SectionKind::getThreadBSS());
9392

9493
// TODO: Verify datarel below.
9594
TLSTLVSection // .tlv
96-
= Ctx->getMachOSection("__DATA", "__thread_vars",
97-
MachO::S_THREAD_LOCAL_VARIABLES,
98-
SectionKind::getDataRel());
95+
= Ctx->getMachOSection("__DATA", "__thread_vars",
96+
MachO::S_THREAD_LOCAL_VARIABLES,
97+
SectionKind::getData());
9998

100-
TLSThreadInitSection
101-
= Ctx->getMachOSection("__DATA", "__thread_init",
102-
MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
103-
SectionKind::getDataRel());
99+
TLSThreadInitSection = Ctx->getMachOSection(
100+
"__DATA", "__thread_init", MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
101+
SectionKind::getData());
104102

105103
CStringSection // .cstring
106104
= Ctx->getMachOSection("__TEXT", "__cstring",
@@ -145,10 +143,8 @@ void MCObjectFileInfo::initMachOMCObjectFileInfo(Triple T) {
145143
= Ctx->getMachOSection("__TEXT", "__const_coal",
146144
MachO::S_COALESCED,
147145
SectionKind::getReadOnly());
148-
DataCoalSection
149-
= Ctx->getMachOSection("__DATA","__datacoal_nt",
150-
MachO::S_COALESCED,
151-
SectionKind::getDataRel());
146+
DataCoalSection = Ctx->getMachOSection(
147+
"__DATA", "__datacoal_nt", MachO::S_COALESCED, SectionKind::getData());
152148
} else {
153149
TextCoalSection = TextSection;
154150
ConstTextCoalSection = ReadOnlySection;
@@ -177,21 +173,17 @@ void MCObjectFileInfo::initMachOMCObjectFileInfo(Triple T) {
177173
SectionKind::getMetadata());
178174

179175
if (RelocM == Reloc::Static) {
180-
StaticCtorSection
181-
= Ctx->getMachOSection("__TEXT", "__constructor", 0,
182-
SectionKind::getDataRel());
183-
StaticDtorSection
184-
= Ctx->getMachOSection("__TEXT", "__destructor", 0,
185-
SectionKind::getDataRel());
176+
StaticCtorSection = Ctx->getMachOSection("__TEXT", "__constructor", 0,
177+
SectionKind::getData());
178+
StaticDtorSection = Ctx->getMachOSection("__TEXT", "__destructor", 0,
179+
SectionKind::getData());
186180
} else {
187-
StaticCtorSection
188-
= Ctx->getMachOSection("__DATA", "__mod_init_func",
189-
MachO::S_MOD_INIT_FUNC_POINTERS,
190-
SectionKind::getDataRel());
191-
StaticDtorSection
192-
= Ctx->getMachOSection("__DATA", "__mod_term_func",
193-
MachO::S_MOD_TERM_FUNC_POINTERS,
194-
SectionKind::getDataRel());
181+
StaticCtorSection = Ctx->getMachOSection("__DATA", "__mod_init_func",
182+
MachO::S_MOD_INIT_FUNC_POINTERS,
183+
SectionKind::getData());
184+
StaticDtorSection = Ctx->getMachOSection("__DATA", "__mod_term_func",
185+
MachO::S_MOD_TERM_FUNC_POINTERS,
186+
SectionKind::getData());
195187
}
196188

197189
// Exception Handling.
@@ -452,9 +444,6 @@ void MCObjectFileInfo::initELFMCObjectFileInfo(Triple T) {
452444
TLSBSSSection = Ctx->getELFSection(
453445
".tbss", ELF::SHT_NOBITS, ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
454446

455-
DataRelSection = Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
456-
ELF::SHF_ALLOC | ELF::SHF_WRITE);
457-
458447
DataRelROSection = Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
459448
ELF::SHF_ALLOC | ELF::SHF_WRITE);
460449

@@ -556,7 +545,7 @@ void MCObjectFileInfo::initCOFFMCObjectFileInfo(Triple T) {
556545
EHFrameSection = Ctx->getCOFFSection(
557546
".eh_frame", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
558547
COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
559-
SectionKind::getDataRel());
548+
SectionKind::getData());
560549

561550
bool IsWoA = T.getArch() == Triple::arm || T.getArch() == Triple::thumb;
562551

@@ -576,7 +565,7 @@ void MCObjectFileInfo::initCOFFMCObjectFileInfo(Triple T) {
576565
DataSection = Ctx->getCOFFSection(
577566
".data", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
578567
COFF::IMAGE_SCN_MEM_WRITE,
579-
SectionKind::getDataRel());
568+
SectionKind::getData());
580569
ReadOnlySection = Ctx->getCOFFSection(
581570
".rdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
582571
SectionKind::getReadOnly());
@@ -594,11 +583,11 @@ void MCObjectFileInfo::initCOFFMCObjectFileInfo(Triple T) {
594583
StaticCtorSection = Ctx->getCOFFSection(
595584
".ctors", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
596585
COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
597-
SectionKind::getDataRel());
586+
SectionKind::getData());
598587
StaticDtorSection = Ctx->getCOFFSection(
599588
".dtors", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
600589
COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
601-
SectionKind::getDataRel());
590+
SectionKind::getData());
602591
}
603592

604593
// FIXME: We're emitting LSDA info into a readonly section on COFF, even
@@ -751,19 +740,19 @@ void MCObjectFileInfo::initCOFFMCObjectFileInfo(Triple T) {
751740

752741
PDataSection = Ctx->getCOFFSection(
753742
".pdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
754-
SectionKind::getDataRel());
743+
SectionKind::getData());
755744

756745
XDataSection = Ctx->getCOFFSection(
757746
".xdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
758-
SectionKind::getDataRel());
747+
SectionKind::getData());
759748

760749
SXDataSection = Ctx->getCOFFSection(".sxdata", COFF::IMAGE_SCN_LNK_INFO,
761750
SectionKind::getMetadata());
762751

763752
TLSDataSection = Ctx->getCOFFSection(
764753
".tls$", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
765754
COFF::IMAGE_SCN_MEM_WRITE,
766-
SectionKind::getDataRel());
755+
SectionKind::getData());
767756

768757
StackMapSection = Ctx->getCOFFSection(".llvm_stackmaps",
769758
COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |

llvm/lib/MC/MCParser/COFFAsmParser.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,10 @@ class COFFAsmParser : public MCAsmParserExtension {
9898
SectionKind::getText());
9999
}
100100
bool ParseSectionDirectiveData(StringRef, SMLoc) {
101-
return ParseSectionSwitch(".data",
102-
COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
103-
| COFF::IMAGE_SCN_MEM_READ
104-
| COFF::IMAGE_SCN_MEM_WRITE,
105-
SectionKind::getDataRel());
101+
return ParseSectionSwitch(".data", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
102+
COFF::IMAGE_SCN_MEM_READ |
103+
COFF::IMAGE_SCN_MEM_WRITE,
104+
SectionKind::getData());
106105
}
107106
bool ParseSectionDirectiveBSS(StringRef, SMLoc) {
108107
return ParseSectionSwitch(".bss",
@@ -153,7 +152,7 @@ static SectionKind computeSectionKind(unsigned Flags) {
153152
if (Flags & COFF::IMAGE_SCN_MEM_READ &&
154153
(Flags & COFF::IMAGE_SCN_MEM_WRITE) == 0)
155154
return SectionKind::getReadOnly();
156-
return SectionKind::getDataRel();
155+
return SectionKind::getData();
157156
}
158157

159158
bool COFFAsmParser::ParseSectionFlags(StringRef FlagsString, unsigned* Flags) {

llvm/lib/MC/MCParser/DarwinAsmParser.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -390,9 +390,8 @@ bool DarwinAsmParser::parseSectionSwitch(const char *Segment,
390390
// FIXME: Arch specific.
391391
bool isText = TAA & MachO::S_ATTR_PURE_INSTRUCTIONS;
392392
getStreamer().SwitchSection(getContext().getMachOSection(
393-
Segment, Section, TAA, StubSize,
394-
isText ? SectionKind::getText()
395-
: SectionKind::getDataRel()));
393+
Segment, Section, TAA, StubSize,
394+
isText ? SectionKind::getText() : SectionKind::getData()));
396395

397396
// Set the implicit alignment, if any.
398397
//
@@ -614,9 +613,8 @@ bool DarwinAsmParser::parseDirectiveSection(StringRef, SMLoc) {
614613
// FIXME: Arch specific.
615614
bool isText = Segment == "__TEXT"; // FIXME: Hack.
616615
getStreamer().SwitchSection(getContext().getMachOSection(
617-
Segment, Section, TAA, StubSize,
618-
isText ? SectionKind::getText()
619-
: SectionKind::getDataRel()));
616+
Segment, Section, TAA, StubSize,
617+
isText ? SectionKind::getText() : SectionKind::getData()));
620618
return false;
621619
}
622620

llvm/lib/MC/MCParser/ELFAsmParser.cpp

+6-8
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ class ELFAsmParser : public MCAsmParserExtension {
7979
// the best way for us to get access to it?
8080
bool ParseSectionDirectiveData(StringRef, SMLoc) {
8181
return ParseSectionSwitch(".data", ELF::SHT_PROGBITS,
82-
ELF::SHF_WRITE |ELF::SHF_ALLOC,
83-
SectionKind::getDataRel());
82+
ELF::SHF_WRITE | ELF::SHF_ALLOC,
83+
SectionKind::getData());
8484
}
8585
bool ParseSectionDirectiveText(StringRef, SMLoc) {
8686
return ParseSectionSwitch(".text", ELF::SHT_PROGBITS,
@@ -111,9 +111,8 @@ class ELFAsmParser : public MCAsmParserExtension {
111111
}
112112
bool ParseSectionDirectiveDataRel(StringRef, SMLoc) {
113113
return ParseSectionSwitch(".data.rel", ELF::SHT_PROGBITS,
114-
ELF::SHF_ALLOC |
115-
ELF::SHF_WRITE,
116-
SectionKind::getDataRel());
114+
ELF::SHF_ALLOC | ELF::SHF_WRITE,
115+
SectionKind::getData());
117116
}
118117
bool ParseSectionDirectiveDataRelRo(StringRef, SMLoc) {
119118
return ParseSectionSwitch(".data.rel.ro", ELF::SHT_PROGBITS,
@@ -123,9 +122,8 @@ class ELFAsmParser : public MCAsmParserExtension {
123122
}
124123
bool ParseSectionDirectiveEhFrame(StringRef, SMLoc) {
125124
return ParseSectionSwitch(".eh_frame", ELF::SHT_PROGBITS,
126-
ELF::SHF_ALLOC |
127-
ELF::SHF_WRITE,
128-
SectionKind::getDataRel());
125+
ELF::SHF_ALLOC | ELF::SHF_WRITE,
126+
SectionKind::getData());
129127
}
130128
bool ParseDirectivePushSection(StringRef, SMLoc);
131129
bool ParseDirectivePopSection(StringRef, SMLoc);

llvm/lib/MC/MCWinEH.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ static MCSection *getUnwindInfoSection(StringRef SecName,
4949
if (CodeSecName.startswith(".text$"))
5050
CodeSecName = CodeSecName.substr(6);
5151

52-
return Context.getCOFFSection(
53-
(SecName + Twine('$') + CodeSecName).str(),
54-
COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
55-
SectionKind::getDataRel());
52+
return Context.getCOFFSection((SecName + Twine('$') + CodeSecName).str(),
53+
COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
54+
COFF::IMAGE_SCN_MEM_READ,
55+
SectionKind::getData());
5656
}
5757
}
5858

llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp

+4-9
Original file line numberDiff line numberDiff line change
@@ -1079,19 +1079,14 @@ inline void ARMELFStreamer::SwitchToEHSection(const char *Prefix,
10791079
}
10801080

10811081
inline void ARMELFStreamer::SwitchToExTabSection(const MCSymbol &FnStart) {
1082-
SwitchToEHSection(".ARM.extab",
1083-
ELF::SHT_PROGBITS,
1084-
ELF::SHF_ALLOC,
1085-
SectionKind::getDataRel(),
1086-
FnStart);
1082+
SwitchToEHSection(".ARM.extab", ELF::SHT_PROGBITS, ELF::SHF_ALLOC,
1083+
SectionKind::getData(), FnStart);
10871084
}
10881085

10891086
inline void ARMELFStreamer::SwitchToExIdxSection(const MCSymbol &FnStart) {
1090-
SwitchToEHSection(".ARM.exidx",
1091-
ELF::SHT_ARM_EXIDX,
1087+
SwitchToEHSection(".ARM.exidx", ELF::SHT_ARM_EXIDX,
10921088
ELF::SHF_ALLOC | ELF::SHF_LINK_ORDER,
1093-
SectionKind::getDataRel(),
1094-
FnStart);
1089+
SectionKind::getData(), FnStart);
10951090
}
10961091
void ARMELFStreamer::EmitFixup(const MCExpr *Expr, MCFixupKind Kind) {
10971092
MCDataFragment *Frag = getOrCreateDataFragment();

0 commit comments

Comments
 (0)