summaryrefslogtreecommitdiff
path: root/lld
diff options
context:
space:
mode:
authorRoland McGrath <mcgrathr@google.com>2023-05-16 13:35:35 -0700
committerRoland McGrath <mcgrathr@google.com>2023-05-16 14:59:36 -0700
commit9d37ea95df1b84cca9b5e954d8964c976a5e303e (patch)
tree2a47d8729db6a15944bf82d685fcacd35f361642 /lld
parent114bc867731acf4a3f46d40adf08ceed740f7d44 (diff)
downloadllvm-9d37ea95df1b84cca9b5e954d8964c976a5e303e.tar.gz
[lld][RISCV] Handle relaxation reductions of more than 65536 bytes
In a real-world case with functions that have many, many R_RISCV_CALL_PLT relocations due to asan and ubsan instrumentation, all these can be relaxed by an instruction and the net result is more than 65536 bytes of reduction in the output .text section that totals about 1.2MiB in final size. This changes InputSection to use a 32-bit field for bytesDropped. The RISCV relaxation keeps track in a 64-bit field and detects 32-bit overflow as it previously detected 16-bit overflow. It doesn't seem likely that 32-bit overflow will arise, but it's not inconceivable and it's cheap enough to detect it. This unfortunately increases the size of InputSection on 64-bit hosts by a word, but that seems hard to avoid. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D150722
Diffstat (limited to 'lld')
-rw-r--r--lld/ELF/Arch/RISCV.cpp6
-rw-r--r--lld/ELF/InputSection.h4
2 files changed, 5 insertions, 5 deletions
diff --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp
index aa67617a5be2..018da8a6e247 100644
--- a/lld/ELF/Arch/RISCV.cpp
+++ b/lld/ELF/Arch/RISCV.cpp
@@ -663,7 +663,7 @@ static bool relax(InputSection &sec) {
auto &aux = *sec.relaxAux;
bool changed = false;
ArrayRef<SymbolAnchor> sa = ArrayRef(aux.anchors);
- uint32_t delta = 0;
+ uint64_t delta = 0;
std::fill_n(aux.relocTypes.get(), sec.relocs().size(), R_RISCV_NONE);
aux.writes.clear();
@@ -726,8 +726,8 @@ static bool relax(InputSection &sec) {
a.d->value = a.offset - delta;
}
// Inform assignAddresses that the size has changed.
- if (!isUInt<16>(delta))
- fatal("section size decrease is too large");
+ if (!isUInt<32>(delta))
+ fatal("section size decrease is too large: " + Twine(delta));
sec.bytesDropped = delta;
return changed;
}
diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h
index 356ccda2d743..143384b3ba7b 100644
--- a/lld/ELF/InputSection.h
+++ b/lld/ELF/InputSection.h
@@ -137,7 +137,7 @@ public:
// Used by --optimize-bb-jumps and RISC-V linker relaxation temporarily to
// indicate the number of bytes which is not counted in the size. This should
// be reset to zero after uses.
- uint16_t bytesDropped = 0;
+ uint32_t bytesDropped = 0;
mutable bool compressed = false;
@@ -401,7 +401,7 @@ private:
template <class ELFT> void copyShtGroup(uint8_t *buf);
};
-static_assert(sizeof(InputSection) <= 152, "InputSection is too big");
+static_assert(sizeof(InputSection) <= 160, "InputSection is too big");
class SyntheticSection : public InputSection {
public: