Skip to content
This repository was archived by the owner on Dec 20, 2019. It is now read-only.

Commit 8655f32

Browse files
committed
LDC: Apply Joakim's Android patches for respective targets
1 parent bf50dba commit 8655f32

7 files changed

+48
-25
lines changed

lib/CodeGen/TargetLoweringObjectFileImpl.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ const MCExpr *TargetLoweringObjectFileELF::getTTypeGlobalReference(
109109
MMI, Streamer);
110110
}
111111

112-
static SectionKind
113-
getELFKindForNamedSection(StringRef Name, SectionKind K) {
112+
static SectionKind getELFKindForNamedSection(StringRef Name, SectionKind K,
113+
const Triple &TargetTriple) {
114114
// N.B.: The defaults used in here are no the same ones used in MC.
115115
// We follow gcc, MC follows gas. For example, given ".section .eh_frame",
116116
// both gas and MC will produce a section with no flags. Given
@@ -141,6 +141,7 @@ getELFKindForNamedSection(StringRef Name, SectionKind K) {
141141
return SectionKind::getThreadData();
142142

143143
if (Name == ".tbss" ||
144+
(TargetTriple.isAndroid() && Name == ".tcommon") || // LDC
144145
Name.startswith(".tbss.") ||
145146
Name.startswith(".gnu.linkonce.tb.") ||
146147
Name.startswith(".llvm.linkonce.tb."))
@@ -172,7 +173,7 @@ static unsigned getELFSectionType(StringRef Name, SectionKind K) {
172173
return ELF::SHT_PROGBITS;
173174
}
174175

175-
static unsigned getELFSectionFlags(SectionKind K) {
176+
static unsigned getELFSectionFlags(SectionKind K, const Triple &TargetTriple) {
176177
unsigned Flags = 0;
177178

178179
if (!K.isMetadata())
@@ -187,7 +188,7 @@ static unsigned getELFSectionFlags(SectionKind K) {
187188
if (K.isWriteable())
188189
Flags |= ELF::SHF_WRITE;
189190

190-
if (K.isThreadLocal())
191+
if (K.isThreadLocal() && !TargetTriple.isAndroid()) // LDC
191192
Flags |= ELF::SHF_TLS;
192193

193194
if (K.isMergeableCString() || K.isMergeableConst())
@@ -216,10 +217,10 @@ MCSection *TargetLoweringObjectFileELF::getExplicitSectionGlobal(
216217
StringRef SectionName = GO->getSection();
217218

218219
// Infer section flags from the section name if we can.
219-
Kind = getELFKindForNamedSection(SectionName, Kind);
220+
Kind = getELFKindForNamedSection(SectionName, Kind, getTargetTriple());
220221

221222
StringRef Group = "";
222-
unsigned Flags = getELFSectionFlags(Kind);
223+
unsigned Flags = getELFSectionFlags(Kind, getTargetTriple());
223224
if (const Comdat *C = getELFComdat(GO)) {
224225
Group = C->getName();
225226
Flags |= ELF::SHF_GROUP;
@@ -324,7 +325,7 @@ selectELFSectionForGlobal(MCContext &Ctx, const GlobalObject *GO,
324325

325326
MCSection *TargetLoweringObjectFileELF::SelectSectionForGlobal(
326327
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
327-
unsigned Flags = getELFSectionFlags(Kind);
328+
unsigned Flags = getELFSectionFlags(Kind, getTargetTriple());
328329

329330
// If we have -ffunction-section or -fdata-section then we should emit the
330331
// global value to a uniqued section specifically for it.

lib/MC/MCELFStreamer.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,12 @@ void MCELFStreamer::fixSymbolsInTLSFixups(const MCExpr *expr) {
450450
break;
451451
}
452452
getAssembler().registerSymbol(symRef.getSymbol());
453-
cast<MCSymbolELF>(symRef.getSymbol()).setType(ELF::STT_TLS);
453+
// LDC
454+
{
455+
auto ofi = getContext().getObjectFileInfo();
456+
if (!(ofi && ofi->getTargetTriple().isAndroid()))
457+
cast<MCSymbolELF>(symRef.getSymbol()).setType(ELF::STT_TLS);
458+
}
454459
break;
455460
}
456461

lib/MC/MCObjectFileInfo.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -467,12 +467,14 @@ void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T) {
467467
ReadOnlySection =
468468
Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
469469

470-
TLSDataSection =
471-
Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
472-
ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
470+
// LDC
471+
const auto tlsFlag = (!getTargetTriple().isAndroid() ? ELF::SHF_TLS : 0);
473472

474-
TLSBSSSection = Ctx->getELFSection(
475-
".tbss", ELF::SHT_NOBITS, ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
473+
TLSDataSection = Ctx->getELFSection(
474+
".tdata", ELF::SHT_PROGBITS, ELF::SHF_ALLOC | tlsFlag | ELF::SHF_WRITE);
475+
476+
TLSBSSSection = Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
477+
ELF::SHF_ALLOC | tlsFlag | ELF::SHF_WRITE);
476478

477479
DataRelROSection = Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
478480
ELF::SHF_ALLOC | ELF::SHF_WRITE);

lib/Target/ARM/MCTargetDesc/ARMAsmBackendELF.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@ using namespace llvm;
1616

1717
namespace {
1818
class ARMAsmBackendELF : public ARMAsmBackend {
19+
// LDC
20+
const bool isAndroid;
21+
1922
public:
2023
uint8_t OSABI;
2124
ARMAsmBackendELF(const Target &T, const Triple &TT, uint8_t OSABI,
2225
bool IsLittle)
23-
: ARMAsmBackend(T, TT, IsLittle), OSABI(OSABI) {}
26+
: ARMAsmBackend(T, TT, IsLittle), isAndroid(TT.isAndroid()),
27+
OSABI(OSABI) {}
2428

2529
MCObjectWriter *createObjectWriter(raw_pwrite_stream &OS) const override {
26-
return createARMELFObjectWriter(OS, OSABI, isLittle());
30+
return createARMELFObjectWriter(OS, OSABI, isLittle(), isAndroid);
2731
}
2832
};
2933
}

lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp

+13-8
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@ using namespace llvm;
2323

2424
namespace {
2525
class ARMELFObjectWriter : public MCELFObjectTargetWriter {
26+
// LDC
27+
const bool isAndroid;
28+
2629
enum { DefaultEABIVersion = 0x05000000U };
2730
unsigned GetRelocTypeInner(const MCValue &Target,
2831
const MCFixup &Fixup,
2932
bool IsPCRel) const;
3033

3134

3235
public:
33-
ARMELFObjectWriter(uint8_t OSABI);
36+
ARMELFObjectWriter(uint8_t OSABI, bool IsAndroid);
3437

3538
~ARMELFObjectWriter() override;
3639

@@ -42,10 +45,10 @@ namespace {
4245
};
4346
}
4447

45-
ARMELFObjectWriter::ARMELFObjectWriter(uint8_t OSABI)
46-
: MCELFObjectTargetWriter(/*Is64Bit*/ false, OSABI,
47-
ELF::EM_ARM,
48-
/*HasRelocationAddend*/ false) {}
48+
ARMELFObjectWriter::ARMELFObjectWriter(uint8_t OSABI, bool IsAndroid)
49+
: MCELFObjectTargetWriter(/*Is64Bit*/ false, OSABI, ELF::EM_ARM,
50+
/*HasRelocationAddend*/ false),
51+
isAndroid(IsAndroid) {}
4952

5053
ARMELFObjectWriter::~ARMELFObjectWriter() {}
5154

@@ -189,7 +192,8 @@ unsigned ARMELFObjectWriter::GetRelocTypeInner(const MCValue &Target,
189192
Type = ELF::R_ARM_GOT_BREL;
190193
break;
191194
case MCSymbolRefExpr::VK_TLSGD:
192-
Type = ELF::R_ARM_TLS_GD32;
195+
// LDC
196+
Type = (isAndroid ? ELF::R_ARM_GOT_PREL : ELF::R_ARM_TLS_GD32);
193197
break;
194198
case MCSymbolRefExpr::VK_TPOFF:
195199
Type = ELF::R_ARM_TLS_LE32;
@@ -283,7 +287,8 @@ unsigned ARMELFObjectWriter::GetRelocTypeInner(const MCValue &Target,
283287

284288
MCObjectWriter *llvm::createARMELFObjectWriter(raw_pwrite_stream &OS,
285289
uint8_t OSABI,
286-
bool IsLittleEndian) {
287-
MCELFObjectTargetWriter *MOTW = new ARMELFObjectWriter(OSABI);
290+
bool IsLittleEndian,
291+
bool IsAndroid) {
292+
MCELFObjectTargetWriter *MOTW = new ARMELFObjectWriter(OSABI, IsAndroid);
288293
return createELFObjectWriter(MOTW, OS, IsLittleEndian);
289294
}

lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ MCStreamer *createARMWinCOFFStreamer(MCContext &Context, MCAsmBackend &MAB,
9999

100100
/// Construct an ELF Mach-O object writer.
101101
MCObjectWriter *createARMELFObjectWriter(raw_pwrite_stream &OS, uint8_t OSABI,
102-
bool IsLittleEndian);
102+
bool IsLittleEndian, bool IsAndroid);
103103

104104
/// Construct an ARM Mach-O object writer.
105105
MCObjectWriter *createARMMachObjectWriter(raw_pwrite_stream &OS, bool Is64Bit,

lib/Target/X86/MCTargetDesc/X86ELFObjectWriter.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "llvm/MC/MCContext.h"
1414
#include "llvm/MC/MCELFObjectWriter.h"
1515
#include "llvm/MC/MCExpr.h"
16+
#include "llvm/MC/MCObjectFileInfo.h" // LDC
1617
#include "llvm/MC/MCValue.h"
1718
#include "llvm/Support/ELF.h"
1819
#include "llvm/Support/ErrorHandling.h"
@@ -253,7 +254,12 @@ static unsigned getRelocType32(MCContext &Ctx,
253254
case MCSymbolRefExpr::VK_TLSGD:
254255
assert(Type == RT32_32);
255256
assert(!IsPCRel);
256-
return ELF::R_386_TLS_GD;
257+
// LDC
258+
{
259+
auto ofi = Ctx.getObjectFileInfo();
260+
return ofi && ofi->getTargetTriple().isAndroid() ? ELF::R_386_GOT32
261+
: ELF::R_386_TLS_GD;
262+
}
257263
case MCSymbolRefExpr::VK_GOTTPOFF:
258264
assert(Type == RT32_32);
259265
assert(!IsPCRel);

0 commit comments

Comments
 (0)