[PATCH] D118692: [llvm-objcopy][COFF] Fix section name encoding
Martin Storsjö via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 19 11:44:11 PST 2022
mstorsjo added a comment.
@jhenderson Can you have another look at this? I ran into the issue that this patch is fixing (discussion in https://github.com/msys2/MINGW-packages/pull/10555#issuecomment-1046014913), and if at all possible, I'd like to have the fix for this issue in the 14.0.x branch (as we're only just past rc1, there should still be time for valuable bug fixes IMO).
What do you think about that? Alternatively, if this feels too big to cherrypick (IMO it isn't), I could fix the simplest part of the issue with a smaller patch like this:
diff --git a/llvm/lib/ObjCopy/COFF/Writer.cpp b/llvm/lib/ObjCopy/COFF/Writer.cpp
index cbd0e4261238..c7928b009b5d 100644
--- a/llvm/lib/ObjCopy/COFF/Writer.cpp
+++ b/llvm/lib/ObjCopy/COFF/Writer.cpp
@@ -130,8 +130,10 @@ size_t COFFWriter::finalizeStringTable() {
for (auto &S : Obj.getMutableSections()) {
memset(S.Header.Name, 0, sizeof(S.Header.Name));
if (S.Name.size() > COFF::NameSize) {
- snprintf(S.Header.Name, sizeof(S.Header.Name), "/%d",
+ char Buf[COFF::NameSize + 1]{};
+ snprintf(Buf, sizeof(Buf), "/%d",
(int)StrTabBuilder.getOffset(S.Name));
+ memcpy(S.Header.Name, Buf, COFF::NameSize);
} else {
memcpy(S.Header.Name, S.Name.data(), S.Name.size());
}
(This would fix the bug I ran into, where the bug appears with string tables over 10^6 bytes. This minimal patch makes things work with string tables up to 10^7 bytes - while the patch under review here handles it even further than that.)
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D118692/new/
https://reviews.llvm.org/D118692
More information about the llvm-commits
mailing list