[llvm-branch-commits] [llvm] 8e7ae35 - [llvm-objcopy] Avoid invalid Sec.Offset after D79229
Fangrui Song via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sun May 3 22:07:08 PDT 2020
Author: Fangrui Song
Date: 2020-05-03T22:06:33-07:00
New Revision: 8e7ae355ba97d6ac0020e11a0efeddc454b9f933
URL: https://github.com/llvm/llvm-project/commit/8e7ae355ba97d6ac0020e11a0efeddc454b9f933
DIFF: https://github.com/llvm/llvm-project/commit/8e7ae355ba97d6ac0020e11a0efeddc454b9f933.diff
LOG: [llvm-objcopy] Avoid invalid Sec.Offset after D79229
To avoid undefined behavior caught by -fsanitize=undefined on binary-paddr.test
void SectionWriter::visit(const Section &Sec) {
if (Sec.Type != SHT_NOBITS)
// Sec.Contents is empty while Sec.Offset may be out of bound
llvm::copy(Sec.Contents, Out.getBufferStart() + Sec.Offset);
}
(cherry picked from commit 762fb1c40eea6878c2d6a1f0f1fc7915c8747981)
Added:
Modified:
llvm/tools/llvm-objcopy/ELF/Object.cpp
Removed:
################################################################################
diff --git a/llvm/tools/llvm-objcopy/ELF/Object.cpp b/llvm/tools/llvm-objcopy/ELF/Object.cpp
index 98f72959ae55..5e5ed95de743 100644
--- a/llvm/tools/llvm-objcopy/ELF/Object.cpp
+++ b/llvm/tools/llvm-objcopy/ELF/Object.cpp
@@ -2271,11 +2271,11 @@ Error BinaryWriter::finalize() {
// layoutSections, because we want to truncate the last segment to the end of
// its last non-empty section, to match GNU objcopy's behaviour.
TotalSize = 0;
- for (SectionBase &Sec : Obj.allocSections()) {
- Sec.Offset = Sec.Addr - MinAddr;
- if (Sec.Type != SHT_NOBITS && Sec.Size > 0)
+ for (SectionBase &Sec : Obj.allocSections())
+ if (Sec.Type != SHT_NOBITS && Sec.Size > 0) {
+ Sec.Offset = Sec.Addr - MinAddr;
TotalSize = std::max(TotalSize, Sec.Offset + Sec.Size);
- }
+ }
if (Error E = Buf.allocate(TotalSize))
return E;
More information about the llvm-branch-commits
mailing list