[llvm] [yaml2obj][XOFF] Update yaml2obj for XCOFF to create valid XCOFF files in more cases. (PR #77620)
James Henderson via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 16 01:04:04 PST 2024
================
@@ -98,11 +98,26 @@ bool XCOFFWriter::nameShouldBeInStringTable(StringRef SymbolName) {
bool XCOFFWriter::initRelocations(uint64_t &CurrentOffset) {
for (XCOFFYAML::Section &InitSection : InitSections) {
if (!InitSection.Relocations.empty()) {
- InitSection.NumberOfRelocations = InitSection.Relocations.size();
- InitSection.FileOffsetToRelocations = CurrentOffset;
uint64_t RelSize = Is64Bit ? XCOFF::RelocationSerializationSize64
: XCOFF::RelocationSerializationSize32;
- CurrentOffset += InitSection.NumberOfRelocations * RelSize;
+ const uint64_t UsedSize = RelSize * InitSection.Relocations.size();
+
+ // If NumberOfRelocations was specified, we use it, even if it's
+ // not consistent with the number of provided relocations
+ if (!InitSection.NumberOfRelocations)
+ InitSection.NumberOfRelocations = InitSection.Relocations.size();
+
+ // If the YAML file specified an offset to relocations, we use it.
+ if (InitSection.FileOffsetToRelocations) {
+ if (CurrentOffset > InitSection.FileOffsetToRelocations) {
+ ErrHandler("Specified FileOffsetToRelocations will overwrite"
+ "existing data");
----------------
jh7370 wrote:
Nit: this does not conform to the error/warning message style in the coding standards (lower-case first letter needed, plus additional context, e.g. what the `CurrentOffset` value actually is).
https://github.com/llvm/llvm-project/pull/77620
More information about the llvm-commits
mailing list