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

Commit f0682e1

Browse files
committed
LDC: Apply Joakim's Android patches for respective targets
1 parent 086f9bf commit f0682e1

7 files changed

+48
-25
lines changed

lib/CodeGen/TargetLoweringObjectFileImpl.cpp

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

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

203203
if (Name == ".tbss" ||
204+
(TargetTriple.isAndroid() && Name == ".tcommon") || // LDC
204205
Name.startswith(".tbss.") ||
205206
Name.startswith(".gnu.linkonce.tb.") ||
206207
Name.startswith(".llvm.linkonce.tb."))
@@ -231,7 +232,7 @@ static unsigned getELFSectionType(StringRef Name, SectionKind K) {
231232
return ELF::SHT_PROGBITS;
232233
}
233234

234-
static unsigned getELFSectionFlags(SectionKind K) {
235+
static unsigned getELFSectionFlags(SectionKind K, const Triple &TargetTriple) {
235236
unsigned Flags = 0;
236237

237238
if (!K.isMetadata())
@@ -246,7 +247,7 @@ static unsigned getELFSectionFlags(SectionKind K) {
246247
if (K.isWriteable())
247248
Flags |= ELF::SHF_WRITE;
248249

249-
if (K.isThreadLocal())
250+
if (K.isThreadLocal() && !TargetTriple.isAndroid()) // LDC
250251
Flags |= ELF::SHF_TLS;
251252

252253
if (K.isMergeableCString() || K.isMergeableConst())
@@ -312,10 +313,10 @@ MCSection *TargetLoweringObjectFileELF::getExplicitSectionGlobal(
312313
}
313314

314315
// Infer section flags from the section name if we can.
315-
Kind = getELFKindForNamedSection(SectionName, Kind);
316+
Kind = getELFKindForNamedSection(SectionName, Kind, getTargetTriple());
316317

317318
StringRef Group = "";
318-
unsigned Flags = getELFSectionFlags(Kind);
319+
unsigned Flags = getELFSectionFlags(Kind, getTargetTriple());
319320
if (const Comdat *C = getELFComdat(GO)) {
320321
Group = C->getName();
321322
Flags |= ELF::SHF_GROUP;
@@ -433,7 +434,7 @@ static MCSectionELF *selectELFSectionForGlobal(
433434

434435
MCSection *TargetLoweringObjectFileELF::SelectSectionForGlobal(
435436
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
436-
unsigned Flags = getELFSectionFlags(Kind);
437+
unsigned Flags = getELFSectionFlags(Kind, getTargetTriple());
437438

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

lib/MC/MCELFStreamer.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,12 @@ void MCELFStreamer::fixSymbolsInTLSFixups(const MCExpr *expr) {
440440
break;
441441
}
442442
getAssembler().registerSymbol(symRef.getSymbol());
443-
cast<MCSymbolELF>(symRef.getSymbol()).setType(ELF::STT_TLS);
443+
// LDC
444+
{
445+
auto ofi = getContext().getObjectFileInfo();
446+
if (!(ofi && ofi->getTargetTriple().isAndroid()))
447+
cast<MCSymbolELF>(symRef.getSymbol()).setType(ELF::STT_TLS);
448+
}
444449
break;
445450
}
446451

lib/MC/MCObjectFileInfo.cpp

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

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

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

486488
DataRelROSection = Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
487489
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
@@ -24,13 +24,16 @@ using namespace llvm;
2424
namespace {
2525

2626
class ARMELFObjectWriter : public MCELFObjectTargetWriter {
27+
// LDC
28+
const bool isAndroid;
29+
2730
enum { DefaultEABIVersion = 0x05000000U };
2831

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

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

3538
~ARMELFObjectWriter() override = default;
3639

@@ -43,10 +46,10 @@ namespace {
4346

4447
} // end anonymous namespace
4548

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

5154
bool ARMELFObjectWriter::needsRelocateWithSymbol(const MCSymbol &Sym,
5255
unsigned Type) const {
@@ -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;
@@ -299,7 +303,8 @@ unsigned ARMELFObjectWriter::GetRelocTypeInner(const MCValue &Target,
299303

300304
MCObjectWriter *llvm::createARMELFObjectWriter(raw_pwrite_stream &OS,
301305
uint8_t OSABI,
302-
bool IsLittleEndian) {
303-
MCELFObjectTargetWriter *MOTW = new ARMELFObjectWriter(OSABI);
306+
bool IsLittleEndian,
307+
bool IsAndroid) {
308+
MCELFObjectTargetWriter *MOTW = new ARMELFObjectWriter(OSABI, IsAndroid);
304309
return createELFObjectWriter(MOTW, OS, IsLittleEndian);
305310
}

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
@@ -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/MCValue.h"
1920
#include "llvm/Support/ErrorHandling.h"
2021
#include <cassert>
@@ -256,7 +257,12 @@ static unsigned getRelocType32(MCContext &Ctx,
256257
case MCSymbolRefExpr::VK_TLSGD:
257258
assert(Type == RT32_32);
258259
assert(!IsPCRel);
259-
return ELF::R_386_TLS_GD;
260+
// LDC
261+
{
262+
auto ofi = Ctx.getObjectFileInfo();
263+
return ofi && ofi->getTargetTriple().isAndroid() ? ELF::R_386_GOT32
264+
: ELF::R_386_TLS_GD;
265+
}
260266
case MCSymbolRefExpr::VK_GOTTPOFF:
261267
assert(Type == RT32_32);
262268
assert(!IsPCRel);

0 commit comments

Comments
 (0)