[PATCH] D43412: Factor out common code from applySecRel functions.
Rui Ueyama via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 17 12:30:37 PST 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL325444: Factor out common code from applySecRel functions. (authored by ruiu, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D43412?vs=134728&id=134814#toc
Repository:
rL LLVM
https://reviews.llvm.org/D43412
Files:
lld/trunk/COFF/Chunks.cpp
Index: lld/trunk/COFF/Chunks.cpp
===================================================================
--- lld/trunk/COFF/Chunks.cpp
+++ lld/trunk/COFF/Chunks.cpp
@@ -51,13 +51,21 @@
static void or16(uint8_t *P, uint16_t V) { write16le(P, read16le(P) | V); }
static void or32(uint8_t *P, uint32_t V) { write32le(P, read32le(P) | V); }
+// Verify that given sections are appropriate targets for SECREL
+// relocations. This check is relaxed because unfortunately debug
+// sections have section-relative relocations against absolute symbols.
+static bool checkSecRel(const SectionChunk *Sec, OutputSection *OS) {
+ if (OS)
+ return true;
+ if (Sec->isCodeView())
+ return false;
+ fatal("SECREL relocation cannot be applied to absolute symbols");
+}
+
static void applySecRel(const SectionChunk *Sec, uint8_t *Off,
OutputSection *OS, uint64_t S) {
- if (!OS) {
- if (Sec->isCodeView())
- return;
- fatal("SECREL relocation cannot be applied to absolute symbols");
- }
+ if (!checkSecRel(Sec, OS))
+ return;
uint64_t SecRel = S - OS->getRVA();
if (SecRel > UINT32_MAX) {
error("overflow in SECREL relocation in section: " + Sec->getSectionName());
@@ -213,16 +221,18 @@
applyArm64Imm(Off, Imm >> Size, Size);
}
-static void applySecRelAdd(const SectionChunk *Sec, uint8_t *Off,
- OutputSection *OS, uint64_t S, int Shift) {
- if (!OS) {
- if (Sec->isCodeView())
- return;
- fatal("SECREL relocation cannot be applied to absolute symbols");
- }
- uint64_t SecRel = S - OS->getRVA();
- SecRel >>= Shift;
- if (Shift > 0 && SecRel > 0xfff) {
+static void applySecRelLow12A(const SectionChunk *Sec, uint8_t *Off,
+ OutputSection *OS, uint64_t S) {
+ if (checkSecRel(Sec, OS))
+ applyArm64Imm(Off, (S - OS->getRVA()) & 0xfff, 0);
+}
+
+static void applySecRelHigh12A(const SectionChunk *Sec, uint8_t *Off,
+ OutputSection *OS, uint64_t S) {
+ if (!checkSecRel(Sec, OS))
+ return;
+ uint64_t SecRel = (S - OS->getRVA()) >> 12;
+ if (0xfff < SecRel) {
error("overflow in SECREL_HIGH12A relocation in section: " +
Sec->getSectionName());
return;
@@ -232,13 +242,8 @@
static void applySecRelLdr(const SectionChunk *Sec, uint8_t *Off,
OutputSection *OS, uint64_t S) {
- if (!OS) {
- if (Sec->isCodeView())
- return;
- fatal("SECREL relocation cannot be applied to absolute symbols");
- }
- uint64_t SecRel = S - OS->getRVA();
- applyArm64Ldr(Off, SecRel & 0xfff);
+ if (checkSecRel(Sec, OS))
+ applyArm64Ldr(Off, (S - OS->getRVA()) & 0xfff);
}
void SectionChunk::applyRelARM64(uint8_t *Off, uint16_t Type, OutputSection *OS,
@@ -252,8 +257,8 @@
case IMAGE_REL_ARM64_ADDR32NB: add32(Off, S); break;
case IMAGE_REL_ARM64_ADDR64: add64(Off, S + Config->ImageBase); break;
case IMAGE_REL_ARM64_SECREL: applySecRel(this, Off, OS, S); break;
- case IMAGE_REL_ARM64_SECREL_LOW12A: applySecRelAdd(this, Off, OS, S, 0); break;
- case IMAGE_REL_ARM64_SECREL_HIGH12A: applySecRelAdd(this, Off, OS, S, 12); break;
+ case IMAGE_REL_ARM64_SECREL_LOW12A: applySecRelLow12A(this, Off, OS, S); break;
+ case IMAGE_REL_ARM64_SECREL_HIGH12A: applySecRelHigh12A(this, Off, OS, S); break;
case IMAGE_REL_ARM64_SECREL_LOW12L: applySecRelLdr(this, Off, OS, S); break;
default:
fatal("unsupported relocation type 0x" + Twine::utohexstr(Type));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43412.134814.patch
Type: text/x-patch
Size: 3514 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180217/5d6259d9/attachment.bin>
More information about the llvm-commits
mailing list