aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Buch <michaelbuch12@gmail.com>2022-12-15 17:57:53 +0000
committerMichael Buch <michaelbuch12@gmail.com>2022-12-15 22:46:43 +0000
commit3db65daa4497beea217c2eb9929ed1f49ba8d40e (patch)
tree6b7e356cfefb66459bc9ebc7812c7f9b1a0a3084
parentc46587bb83232bd639c1e6ba6bce2f290941675d (diff)
downloadllvm-3db65daa4497beea217c2eb9929ed1f49ba8d40e.zip
llvm-3db65daa4497beea217c2eb9929ed1f49ba8d40e.tar.gz
llvm-3db65daa4497beea217c2eb9929ed1f49ba8d40e.tar.bz2
[MachOYAML] Improve section offset misalignment error message
Before: ``` wrote too much data somewhere, section offsets don't line up ``` After: ``` wrote too much data somewhere, section offsets in section __debug_str for segment __DWARF don't line up: [cursor=0x581], [fileStart=0x0], [sectionOffset=0x579] ``` Differential Revision: https://reviews.llvm.org/D140116
-rw-r--r--llvm/lib/ObjectYAML/MachOEmitter.cpp8
-rw-r--r--llvm/test/ObjectYAML/MachO/sections.yaml2
2 files changed, 8 insertions, 2 deletions
diff --git a/llvm/lib/ObjectYAML/MachOEmitter.cpp b/llvm/lib/ObjectYAML/MachOEmitter.cpp
index 022c08e..54983f0 100644
--- a/llvm/lib/ObjectYAML/MachOEmitter.cpp
+++ b/llvm/lib/ObjectYAML/MachOEmitter.cpp
@@ -17,6 +17,7 @@
#include "llvm/ObjectYAML/yaml2obj.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/Error.h"
+#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/LEB128.h"
#include "llvm/Support/YAMLTraits.h"
#include "llvm/Support/raw_ostream.h"
@@ -315,7 +316,12 @@ Error MachOWriter::writeSectionData(raw_ostream &OS) {
if (OS.tell() - fileStart > Sec.offset && Sec.offset != (uint32_t)0)
return createStringError(
errc::invalid_argument,
- "wrote too much data somewhere, section offsets don't line up");
+ llvm::formatv(
+ "wrote too much data somewhere, section offsets in "
+ "section {0} for segment {1} don't line up: "
+ "[cursor={2:x}], [fileStart={3:x}], [sectionOffset={4:x}]",
+ Sec.sectname, Sec.segname, OS.tell(), fileStart,
+ Sec.offset.value));
StringRef SectName(Sec.sectname,
strnlen(Sec.sectname, sizeof(Sec.sectname)));
diff --git a/llvm/test/ObjectYAML/MachO/sections.yaml b/llvm/test/ObjectYAML/MachO/sections.yaml
index 76d6205..052c66f 100644
--- a/llvm/test/ObjectYAML/MachO/sections.yaml
+++ b/llvm/test/ObjectYAML/MachO/sections.yaml
@@ -291,7 +291,7 @@ LoadCommands:
# RUN: not yaml2obj --docnum=2 %s -o %t2.macho 2>&1 | FileCheck %s --check-prefix=OVERLAP
-# OVERLAP: yaml2obj: error: wrote too much data somewhere, section offsets don't line up
+# OVERLAP: yaml2obj: error: wrote too much data somewhere, section offsets in section __sec2 for segment __SEC don't line up: [cursor=0x121], [fileStart=0x0], [sectionOffset=0x1]
--- !mach-o
FileHeader: