Skip to content

Commit 20e5f5e

Browse files
committed
For Darwin, emit all the text section directives together before the dwarf
section directives. This causes the assembler to put the text sections at the beginning of the object file, which helps work around a limitation of the Darwin ARM relocations. Radar 7255355. llvm-svn: 83127
1 parent 10ce958 commit 20e5f5e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

llvm/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,25 @@ void ARMAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
10461046

10471047
bool ARMAsmPrinter::doInitialization(Module &M) {
10481048

1049+
if (Subtarget->isTargetDarwin()) {
1050+
Reloc::Model RelocM = TM.getRelocationModel();
1051+
if (RelocM == Reloc::PIC_ || RelocM == Reloc::DynamicNoPIC) {
1052+
// Declare all the text sections up front (before the DWARF sections
1053+
// emitted by AsmPrinter::doInitialization) so the assembler will keep
1054+
// them together at the beginning of the object file. This helps
1055+
// avoid out-of-range branches that are due a fundamental limitation of
1056+
// the way symbol offsets are encoded with the current Darwin ARM
1057+
// relocations.
1058+
O << "\t.section __TEXT,__text,regular\n"
1059+
<< "\t.section __TEXT,__textcoal_nt,coalesced\n"
1060+
<< "\t.section __TEXT,__const_coal,coalesced\n";
1061+
if (RelocM == Reloc::DynamicNoPIC)
1062+
O << "\t.section __TEXT,__symbol_stub4,symbol_stubs,none,12\n";
1063+
else
1064+
O << "\t.section __TEXT,__picsymbolstub4,symbol_stubs,none,16\n";
1065+
}
1066+
}
1067+
10491068
bool Result = AsmPrinter::doInitialization(M);
10501069
DW = getAnalysisIfAvailable<DwarfWriter>();
10511070

0 commit comments

Comments
 (0)