[llvm-branch-commits] [llvm] [GOFF] Write out relocations in the GOFF writer (PR #167054)
Ulrich Weigand via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Nov 11 02:52:53 PST 2025
================
@@ -502,6 +535,169 @@ void GOFFWriter::writeText(const MCSectionGOFF *Section) {
Asm.writeSectionData(S, Section);
}
+namespace {
+// RelocDataItemBuffer provides a static buffer for relocation data items.
+class RelocDataItemBuffer {
+ char Buffer[GOFF::MaxDataLength];
+ char *Ptr;
+
+public:
+ RelocDataItemBuffer() : Ptr(Buffer) {}
+ const char *data() { return Buffer; }
+ size_t size() { return Ptr - Buffer; }
+ void reset() { Ptr = Buffer; }
+ bool fits(size_t S) { return size() + S < GOFF::MaxDataLength; }
+ template <typename T> void writebe(T Val) {
+ assert(fits(sizeof(T)) && "Out-of-bounds write");
+ support::endian::write<T, llvm::endianness::big>(Ptr, Val);
+ Ptr += sizeof(T);
+ }
+};
+} // namespace
+
+void GOFFWriter::writeRelocations() {
+ // Transform a GOFFSavedRelocationEntry to 1 or 2 GOFFRelocationEntry
+ // instances. An expression like SymA - SymB + Const is implemented by storing
+ // Const in the memory (aka the FixedValue), and then having a relocation to
+ // add SymA, and another relocation to subtract SymB.
+ std::vector<GOFFRelocationEntry> Relocations;
----------------
uweigand wrote:
It is a bit unfortunate that we have *two* temporary relocation buffers; the GOFFSavedRelocationEntry vector in the caller and this GOFFRelocationEntry here. Would there be a way to avoid this second copy? E.g. the caller should already be able to make the decision to create two entries, right? We'd just have to keep MCSymbolGOFF pointers instead of EsdIds, but those could be dereferenced on the fly here, no?
https://github.com/llvm/llvm-project/pull/167054
More information about the llvm-branch-commits
mailing list