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

Commit ae47ad5

Browse files
committed
LDC: Apply Joakim's Android patches for respective targets
1 parent 182459b commit ae47ad5

7 files changed

+50
-25
lines changed

lib/CodeGen/TargetLoweringObjectFileImpl.cpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ const MCExpr *TargetLoweringObjectFileELF::getTTypeGlobalReference(
169169
MMI, Streamer);
170170
}
171171

172-
static SectionKind getELFKindForNamedSection(StringRef Name, SectionKind K) {
172+
static SectionKind getELFKindForNamedSection(StringRef Name, SectionKind K,
173+
const Triple &TargetTriple) {
173174
// N.B.: The defaults used in here are no the same ones used in MC.
174175
// We follow gcc, MC follows gas. For example, given ".section .eh_frame",
175176
// both gas and MC will produce a section with no flags. Given
@@ -201,6 +202,7 @@ static SectionKind getELFKindForNamedSection(StringRef Name, SectionKind K) {
201202
return SectionKind::getThreadData();
202203

203204
if (Name == ".tbss" ||
205+
(TargetTriple.isAndroid() && Name == ".tcommon") || // LDC
204206
Name.startswith(".tbss.") ||
205207
Name.startswith(".gnu.linkonce.tb.") ||
206208
Name.startswith(".llvm.linkonce.tb."))
@@ -231,7 +233,7 @@ static unsigned getELFSectionType(StringRef Name, SectionKind K) {
231233
return ELF::SHT_PROGBITS;
232234
}
233235

234-
static unsigned getELFSectionFlags(SectionKind K) {
236+
static unsigned getELFSectionFlags(SectionKind K, const Triple &TargetTriple) {
235237
unsigned Flags = 0;
236238

237239
if (!K.isMetadata())
@@ -246,7 +248,7 @@ static unsigned getELFSectionFlags(SectionKind K) {
246248
if (K.isWriteable())
247249
Flags |= ELF::SHF_WRITE;
248250

249-
if (K.isThreadLocal())
251+
if (K.isThreadLocal() && !TargetTriple.isAndroid()) // LDC
250252
Flags |= ELF::SHF_TLS;
251253

252254
if (K.isMergeableCString() || K.isMergeableConst())
@@ -312,10 +314,10 @@ MCSection *TargetLoweringObjectFileELF::getExplicitSectionGlobal(
312314
}
313315

314316
// Infer section flags from the section name if we can.
315-
Kind = getELFKindForNamedSection(SectionName, Kind);
317+
Kind = getELFKindForNamedSection(SectionName, Kind, getTargetTriple());
316318

317319
StringRef Group = "";
318-
unsigned Flags = getELFSectionFlags(Kind);
320+
unsigned Flags = getELFSectionFlags(Kind, getTargetTriple());
319321
if (const Comdat *C = getELFComdat(GO)) {
320322
Group = C->getName();
321323
Flags |= ELF::SHF_GROUP;
@@ -433,7 +435,7 @@ static MCSectionELF *selectELFSectionForGlobal(
433435

434436
MCSection *TargetLoweringObjectFileELF::SelectSectionForGlobal(
435437
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
436-
unsigned Flags = getELFSectionFlags(Kind);
438+
unsigned Flags = getELFSectionFlags(Kind, getTargetTriple());
437439

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

lib/MC/MCELFStreamer.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,12 @@ void MCELFStreamer::fixSymbolsInTLSFixups(const MCExpr *expr) {
447447
break;
448448
}
449449
getAssembler().registerSymbol(symRef.getSymbol());
450-
cast<MCSymbolELF>(symRef.getSymbol()).setType(ELF::STT_TLS);
450+
// LDC
451+
{
452+
auto ofi = getContext().getObjectFileInfo();
453+
if (!(ofi && ofi->getTargetTriple().isAndroid()))
454+
cast<MCSymbolELF>(symRef.getSymbol()).setType(ELF::STT_TLS);
455+
}
451456
break;
452457
}
453458

lib/MC/MCObjectFileInfo.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -475,12 +475,14 @@ void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) {
475475
ReadOnlySection =
476476
Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
477477

478-
TLSDataSection =
479-
Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
480-
ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
478+
// LDC
479+
const auto tlsFlag = (!getTargetTriple().isAndroid() ? ELF::SHF_TLS : 0);
481480

482-
TLSBSSSection = Ctx->getELFSection(
483-
".tbss", ELF::SHT_NOBITS, ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
481+
TLSDataSection = Ctx->getELFSection(
482+
".tdata", ELF::SHT_PROGBITS, ELF::SHF_ALLOC | tlsFlag | ELF::SHF_WRITE);
483+
484+
TLSBSSSection = Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
485+
ELF::SHF_ALLOC | tlsFlag | ELF::SHF_WRITE);
484486

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

lib/Target/ARM/MCTargetDesc/ARMAsmBackendELF.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,19 @@ using namespace llvm;
1818

1919
namespace {
2020
class ARMAsmBackendELF : public ARMAsmBackend {
21+
// LDC
22+
const bool isAndroid;
23+
2124
public:
2225
uint8_t OSABI;
2326
ARMAsmBackendELF(const Target &T, const MCSubtargetInfo &STI, uint8_t OSABI,
2427
bool IsLittle)
25-
: ARMAsmBackend(T, STI, IsLittle), OSABI(OSABI) {}
28+
: ARMAsmBackend(T, STI, IsLittle),
29+
isAndroid(STI.getTargetTriple().isAndroid()), OSABI(OSABI) {}
2630

2731
std::unique_ptr<MCObjectWriter>
2832
createObjectWriter(raw_pwrite_stream &OS) const override {
29-
return createARMELFObjectWriter(OS, OSABI, isLittle());
33+
return createARMELFObjectWriter(OS, OSABI, isLittle(), isAndroid);
3034
}
3135
};
3236
}

lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp

+14-9
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,16 @@ using namespace llvm;
2525
namespace {
2626

2727
class ARMELFObjectWriter : public MCELFObjectTargetWriter {
28+
// LDC
29+
const bool isAndroid;
30+
2831
enum { DefaultEABIVersion = 0x05000000U };
2932

3033
unsigned GetRelocTypeInner(const MCValue &Target, const MCFixup &Fixup,
3134
bool IsPCRel, MCContext &Ctx) const;
3235

3336
public:
34-
ARMELFObjectWriter(uint8_t OSABI);
37+
ARMELFObjectWriter(uint8_t OSABI, bool IsAndroid);
3538

3639
~ARMELFObjectWriter() override = default;
3740

@@ -44,10 +47,10 @@ namespace {
4447

4548
} // end anonymous namespace
4649

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

5255
bool ARMELFObjectWriter::needsRelocateWithSymbol(const MCSymbol &Sym,
5356
unsigned Type) const {
@@ -164,7 +167,8 @@ unsigned ARMELFObjectWriter::GetRelocTypeInner(const MCValue &Target,
164167
case MCSymbolRefExpr::VK_GOT:
165168
return ELF::R_ARM_GOT_BREL;
166169
case MCSymbolRefExpr::VK_TLSGD:
167-
return ELF::R_ARM_TLS_GD32;
170+
// LDC
171+
return isAndroid ? ELF::R_ARM_GOT_PREL : ELF::R_ARM_TLS_GD32;
168172
case MCSymbolRefExpr::VK_TPOFF:
169173
return ELF::R_ARM_TLS_LE32;
170174
case MCSymbolRefExpr::VK_GOTTPOFF:
@@ -238,7 +242,8 @@ unsigned ARMELFObjectWriter::GetRelocTypeInner(const MCValue &Target,
238242

239243
std::unique_ptr<MCObjectWriter>
240244
llvm::createARMELFObjectWriter(raw_pwrite_stream &OS, uint8_t OSABI,
241-
bool IsLittleEndian) {
242-
return createELFObjectWriter(llvm::make_unique<ARMELFObjectWriter>(OSABI), OS,
243-
IsLittleEndian);
245+
bool IsLittleEndian, bool IsAndroid) {
246+
return createELFObjectWriter(
247+
llvm::make_unique<ARMELFObjectWriter>(OSABI, IsAndroid), OS,
248+
IsLittleEndian);
244249
}

lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ MCStreamer *createARMWinCOFFStreamer(MCContext &Context,
103103
/// Construct an ELF Mach-O object writer.
104104
std::unique_ptr<MCObjectWriter> createARMELFObjectWriter(raw_pwrite_stream &OS,
105105
uint8_t OSABI,
106-
bool IsLittleEndian);
106+
bool IsLittleEndian,
107+
bool IsAndroid);
107108

108109
/// Construct an ARM Mach-O object writer.
109110
std::unique_ptr<MCObjectWriter> createARMMachObjectWriter(raw_pwrite_stream &OS,

lib/Target/X86/MCTargetDesc/X86ELFObjectWriter.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "llvm/MC/MCELFObjectWriter.h"
1616
#include "llvm/MC/MCExpr.h"
1717
#include "llvm/MC/MCFixup.h"
18+
#include "llvm/MC/MCObjectFileInfo.h" // LDC
1819
#include "llvm/MC/MCObjectWriter.h"
1920
#include "llvm/MC/MCValue.h"
2021
#include "llvm/Support/ErrorHandling.h"
@@ -257,7 +258,12 @@ static unsigned getRelocType32(MCContext &Ctx,
257258
case MCSymbolRefExpr::VK_TLSGD:
258259
assert(Type == RT32_32);
259260
assert(!IsPCRel);
260-
return ELF::R_386_TLS_GD;
261+
// LDC
262+
{
263+
auto ofi = Ctx.getObjectFileInfo();
264+
return ofi && ofi->getTargetTriple().isAndroid() ? ELF::R_386_GOT32
265+
: ELF::R_386_TLS_GD;
266+
}
261267
case MCSymbolRefExpr::VK_GOTTPOFF:
262268
assert(Type == RT32_32);
263269
assert(!IsPCRel);

0 commit comments

Comments
 (0)