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

Commit eb28b87

Browse files
authored
Merge pull request #19 from RadeonOpenCompute/roc-1.6.1
roc-1.6.1 updates
2 parents d31b429 + 0409396 commit eb28b87

File tree

118 files changed

+3784
-509
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+3784
-509
lines changed

COFF/Chunks.cpp

Lines changed: 65 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "Error.h"
1212
#include "InputFiles.h"
1313
#include "Symbols.h"
14+
#include "Writer.h"
1415
#include "llvm/ADT/Twine.h"
1516
#include "llvm/BinaryFormat/COFF.h"
1617
#include "llvm/Object/COFF.h"
@@ -52,9 +53,27 @@ static void add32(uint8_t *P, int32_t V) { write32le(P, read32le(P) + V); }
5253
static void add64(uint8_t *P, int64_t V) { write64le(P, read64le(P) + V); }
5354
static void or16(uint8_t *P, uint16_t V) { write16le(P, read16le(P) | V); }
5455

55-
void SectionChunk::applyRelX64(uint8_t *Off, uint16_t Type, Defined *Sym,
56-
uint64_t P) const {
57-
uint64_t S = Sym->getRVA();
56+
static void applySecRel(const SectionChunk *Sec, uint8_t *Off,
57+
OutputSection *OS, uint64_t S) {
58+
if (!OS) {
59+
if (Sec->isCodeView())
60+
return;
61+
fatal("SECREL relocation cannot be applied to absolute symbols");
62+
}
63+
uint64_t SecRel = S - OS->getRVA();
64+
assert(SecRel < INT32_MAX && "overflow in SECREL relocation");
65+
add32(Off, SecRel);
66+
}
67+
68+
static void applySecIdx(uint8_t *Off, OutputSection *OS) {
69+
// If we have no output section, this must be an absolute symbol. Use the
70+
// sentinel absolute symbol section index.
71+
uint16_t SecIdx = OS ? OS->SectionIndex : DefinedAbsolute::OutputSectionIndex;
72+
add16(Off, SecIdx);
73+
}
74+
75+
void SectionChunk::applyRelX64(uint8_t *Off, uint16_t Type, OutputSection *OS,
76+
uint64_t S, uint64_t P) const {
5877
switch (Type) {
5978
case IMAGE_REL_AMD64_ADDR32: add32(Off, S + Config->ImageBase); break;
6079
case IMAGE_REL_AMD64_ADDR64: add64(Off, S + Config->ImageBase); break;
@@ -65,23 +84,22 @@ void SectionChunk::applyRelX64(uint8_t *Off, uint16_t Type, Defined *Sym,
6584
case IMAGE_REL_AMD64_REL32_3: add32(Off, S - P - 7); break;
6685
case IMAGE_REL_AMD64_REL32_4: add32(Off, S - P - 8); break;
6786
case IMAGE_REL_AMD64_REL32_5: add32(Off, S - P - 9); break;
68-
case IMAGE_REL_AMD64_SECTION: add16(Off, Sym->getSectionIndex()); break;
69-
case IMAGE_REL_AMD64_SECREL: add32(Off, Sym->getSecrel()); break;
87+
case IMAGE_REL_AMD64_SECTION: applySecIdx(Off, OS); break;
88+
case IMAGE_REL_AMD64_SECREL: applySecRel(this, Off, OS, S); break;
7089
default:
7190
fatal("unsupported relocation type 0x" + Twine::utohexstr(Type));
7291
}
7392
}
7493

75-
void SectionChunk::applyRelX86(uint8_t *Off, uint16_t Type, Defined *Sym,
76-
uint64_t P) const {
77-
uint64_t S = Sym->getRVA();
94+
void SectionChunk::applyRelX86(uint8_t *Off, uint16_t Type, OutputSection *OS,
95+
uint64_t S, uint64_t P) const {
7896
switch (Type) {
7997
case IMAGE_REL_I386_ABSOLUTE: break;
8098
case IMAGE_REL_I386_DIR32: add32(Off, S + Config->ImageBase); break;
8199
case IMAGE_REL_I386_DIR32NB: add32(Off, S); break;
82100
case IMAGE_REL_I386_REL32: add32(Off, S - P - 4); break;
83-
case IMAGE_REL_I386_SECTION: add16(Off, Sym->getSectionIndex()); break;
84-
case IMAGE_REL_I386_SECREL: add32(Off, Sym->getSecrel()); break;
101+
case IMAGE_REL_I386_SECTION: applySecIdx(Off, OS); break;
102+
case IMAGE_REL_I386_SECREL: applySecRel(this, Off, OS, S); break;
85103
default:
86104
fatal("unsupported relocation type 0x" + Twine::utohexstr(Type));
87105
}
@@ -128,20 +146,21 @@ static void applyBranch24T(uint8_t *Off, int32_t V) {
128146
write16le(Off + 2, (read16le(Off + 2) & 0xd000) | (J1 << 13) | (J2 << 11) | ((V >> 1) & 0x7ff));
129147
}
130148

131-
void SectionChunk::applyRelARM(uint8_t *Off, uint16_t Type, Defined *Sym,
132-
uint64_t P) const {
133-
uint64_t S = Sym->getRVA();
149+
void SectionChunk::applyRelARM(uint8_t *Off, uint16_t Type, OutputSection *OS,
150+
uint64_t S, uint64_t P) const {
134151
// Pointer to thumb code must have the LSB set.
135-
if (Sym->isExecutable())
136-
S |= 1;
152+
uint64_t SX = S;
153+
if (OS && (OS->getPermissions() & IMAGE_SCN_MEM_EXECUTE))
154+
SX |= 1;
137155
switch (Type) {
138-
case IMAGE_REL_ARM_ADDR32: add32(Off, S + Config->ImageBase); break;
139-
case IMAGE_REL_ARM_ADDR32NB: add32(Off, S); break;
140-
case IMAGE_REL_ARM_MOV32T: applyMOV32T(Off, S + Config->ImageBase); break;
141-
case IMAGE_REL_ARM_BRANCH20T: applyBranch20T(Off, S - P - 4); break;
142-
case IMAGE_REL_ARM_BRANCH24T: applyBranch24T(Off, S - P - 4); break;
143-
case IMAGE_REL_ARM_BLX23T: applyBranch24T(Off, S - P - 4); break;
144-
case IMAGE_REL_ARM_SECREL: add32(Off, Sym->getSecrel()); break;
156+
case IMAGE_REL_ARM_ADDR32: add32(Off, SX + Config->ImageBase); break;
157+
case IMAGE_REL_ARM_ADDR32NB: add32(Off, SX); break;
158+
case IMAGE_REL_ARM_MOV32T: applyMOV32T(Off, SX + Config->ImageBase); break;
159+
case IMAGE_REL_ARM_BRANCH20T: applyBranch20T(Off, SX - P - 4); break;
160+
case IMAGE_REL_ARM_BRANCH24T: applyBranch24T(Off, SX - P - 4); break;
161+
case IMAGE_REL_ARM_BLX23T: applyBranch24T(Off, SX - P - 4); break;
162+
case IMAGE_REL_ARM_SECTION: applySecIdx(Off, OS); break;
163+
case IMAGE_REL_ARM_SECREL: applySecRel(this, Off, OS, S); break;
145164
default:
146165
fatal("unsupported relocation type 0x" + Twine::utohexstr(Type));
147166
}
@@ -157,18 +176,39 @@ void SectionChunk::writeTo(uint8_t *Buf) const {
157176
// Apply relocations.
158177
for (const coff_relocation &Rel : Relocs) {
159178
uint8_t *Off = Buf + OutputSectionOff + Rel.VirtualAddress;
179+
180+
// Get the output section of the symbol for this relocation. The output
181+
// section is needed to compute SECREL and SECTION relocations used in debug
182+
// info.
160183
SymbolBody *Body = File->getSymbolBody(Rel.SymbolTableIndex);
161184
Defined *Sym = cast<Defined>(Body);
185+
Chunk *C = Sym->getChunk();
186+
OutputSection *OS = C ? C->getOutputSection() : nullptr;
187+
188+
// Only absolute and __ImageBase symbols lack an output section. For any
189+
// other symbol, this indicates that the chunk was discarded. Normally
190+
// relocations against discarded sections are an error. However, debug info
191+
// sections are not GC roots and can end up with these kinds of relocations.
192+
// Skip these relocations.
193+
if (!OS && !isa<DefinedAbsolute>(Sym) && !isa<DefinedSynthetic>(Sym)) {
194+
if (isCodeView())
195+
continue;
196+
fatal("relocation against symbol in discarded section: " +
197+
Sym->getName());
198+
}
199+
uint64_t S = Sym->getRVA();
200+
201+
// Compute the RVA of the relocation for relative relocations.
162202
uint64_t P = RVA + Rel.VirtualAddress;
163203
switch (Config->Machine) {
164204
case AMD64:
165-
applyRelX64(Off, Rel.Type, Sym, P);
205+
applyRelX64(Off, Rel.Type, OS, S, P);
166206
break;
167207
case I386:
168-
applyRelX86(Off, Rel.Type, Sym, P);
208+
applyRelX86(Off, Rel.Type, OS, S, P);
169209
break;
170210
case ARMNT:
171-
applyRelARM(Off, Rel.Type, Sym, P);
211+
applyRelARM(Off, Rel.Type, OS, S, P);
172212
break;
173213
default:
174214
llvm_unreachable("unknown machine type");

COFF/Chunks.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,12 @@ class SectionChunk : public Chunk {
145145
StringRef getSectionName() const override { return SectionName; }
146146
void getBaserels(std::vector<Baserel> *Res) override;
147147
bool isCOMDAT() const;
148-
void applyRelX64(uint8_t *Off, uint16_t Type, Defined *Sym, uint64_t P) const;
149-
void applyRelX86(uint8_t *Off, uint16_t Type, Defined *Sym, uint64_t P) const;
150-
void applyRelARM(uint8_t *Off, uint16_t Type, Defined *Sym, uint64_t P) const;
148+
void applyRelX64(uint8_t *Off, uint16_t Type, OutputSection *OS, uint64_t S,
149+
uint64_t P) const;
150+
void applyRelX86(uint8_t *Off, uint16_t Type, OutputSection *OS, uint64_t S,
151+
uint64_t P) const;
152+
void applyRelARM(uint8_t *Off, uint16_t Type, OutputSection *OS, uint64_t S,
153+
uint64_t P) const;
151154

152155
// Called if the garbage collector decides to not include this chunk
153156
// in a final output. It's supposed to print out a log message to stdout.
@@ -177,6 +180,12 @@ class SectionChunk : public Chunk {
177180
// redundant when GC is enabled, as all comdat sections will start out dead.
178181
void markDiscarded() { Discarded = true; }
179182

183+
// True if this is a codeview debug info chunk. These will not be laid out in
184+
// the image. Instead they will end up in the PDB, if one is requested.
185+
bool isCodeView() const {
186+
return SectionName == ".debug" || SectionName.startswith(".debug$");
187+
}
188+
180189
// Allow iteration over the bodies of this chunk's relocated symbols.
181190
llvm::iterator_range<symbol_iterator> symbols() const {
182191
return llvm::make_range(symbol_iterator(File, Relocs.begin()),

COFF/Config.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class SymbolBody;
3131

3232
// Short aliases.
3333
static const auto AMD64 = llvm::COFF::IMAGE_FILE_MACHINE_AMD64;
34+
static const auto ARM64 = llvm::COFF::IMAGE_FILE_MACHINE_ARM64;
3435
static const auto ARMNT = llvm::COFF::IMAGE_FILE_MACHINE_ARMNT;
3536
static const auto I386 = llvm::COFF::IMAGE_FILE_MACHINE_I386;
3637

@@ -73,7 +74,7 @@ enum class DebugType {
7374
// Global configuration.
7475
struct Configuration {
7576
enum ManifestKind { SideBySide, Embed, No };
76-
bool is64() { return Machine == AMD64; }
77+
bool is64() { return Machine == AMD64 || Machine == ARM64; }
7778

7879
llvm::COFF::MachineTypes Machine = IMAGE_FILE_MACHINE_UNKNOWN;
7980
bool Verbose = false;

COFF/Driver.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,17 +1026,21 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
10261026
if (Config->ImageBase == uint64_t(-1))
10271027
Config->ImageBase = getDefaultImageBase();
10281028

1029-
Symtab.addRelative(mangle("__ImageBase"), 0);
1029+
Symtab.addSynthetic(mangle("__ImageBase"), nullptr);
10301030
if (Config->Machine == I386) {
1031-
Config->SEHTable = Symtab.addRelative("___safe_se_handler_table", 0);
1032-
Config->SEHCount = Symtab.addAbsolute("___safe_se_handler_count", 0);
1031+
Symtab.addAbsolute("___safe_se_handler_table", 0);
1032+
Symtab.addAbsolute("___safe_se_handler_count", 0);
10331033
}
10341034

10351035
// We do not support /guard:cf (control flow protection) yet.
10361036
// Define CFG symbols anyway so that we can link MSVC 2015 CRT.
1037-
Symtab.addAbsolute(mangle("__guard_fids_table"), 0);
10381037
Symtab.addAbsolute(mangle("__guard_fids_count"), 0);
1038+
Symtab.addAbsolute(mangle("__guard_fids_table"), 0);
10391039
Symtab.addAbsolute(mangle("__guard_flags"), 0x100);
1040+
Symtab.addAbsolute(mangle("__guard_iat_count"), 0);
1041+
Symtab.addAbsolute(mangle("__guard_iat_table"), 0);
1042+
Symtab.addAbsolute(mangle("__guard_longjmp_count"), 0);
1043+
Symtab.addAbsolute(mangle("__guard_longjmp_table"), 0);
10401044

10411045
// This code may add new undefined symbols to the link, which may enqueue more
10421046
// symbol resolution tasks, so we need to continue executing tasks until we

COFF/Driver.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ extern LinkerDriver *Driver;
3434
using llvm::COFF::MachineTypes;
3535
using llvm::COFF::WindowsSubsystem;
3636
using llvm::Optional;
37-
class InputFile;
3837

3938
// Implemented in MarkLive.cpp.
4039
void markLive(const std::vector<Chunk *> &Chunks);
@@ -178,7 +177,7 @@ void runMSVCLinker(std::string Rsp, ArrayRef<StringRef> Objects);
178177
// Create enum with OPT_xxx values for each option in Options.td
179178
enum {
180179
OPT_INVALID = 0,
181-
#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11) OPT_##ID,
180+
#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11, _12) OPT_##ID,
182181
#include "Options.inc"
183182
#undef OPTION
184183
};

0 commit comments

Comments
 (0)