Index: lld/test/ELF/stdout.s =================================================================== --- lld/test/ELF/stdout.s +++ lld/test/ELF/stdout.s @@ -1,12 +1,15 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o -# RUN: ld.lld %t.o -o - > %t -# RUN: llvm-objdump -d %t | FileCheck %s +# RUN: ld.lld %t.o -o - > %t1 +# RUN: llvm-objdump -d %t1 | FileCheck %s # CHECK: 0000000000201000 _start: # CHECK: 201000: 90 nop +# RUN: ld.lld %t.o -o %t2 +# RUN: diff %t1 %t2 + .globl _start _start: nop Index: llvm/lib/Support/FileOutputBuffer.cpp =================================================================== --- llvm/lib/Support/FileOutputBuffer.cpp +++ llvm/lib/Support/FileOutputBuffer.cpp @@ -77,25 +77,26 @@ class InMemoryBuffer : public FileOutputBuffer { public: InMemoryBuffer(StringRef Path, std::unique_ptr &OS, - MemoryBlock MB) - : FileOutputBuffer(Path), OS(std::move(OS)), MB(MB) {} + MemoryBlock MB, size_t Size) + : FileOutputBuffer(Path), OS(std::move(OS)), MB(MB), Size(Size) {} uint8_t *getBufferStart() const override { return (uint8_t *)MB.base(); } uint8_t *getBufferEnd() const override { - return (uint8_t *)MB.base() + MB.size(); + return (uint8_t *)MB.base() + Size; } - size_t getBufferSize() const override { return MB.size(); } + size_t getBufferSize() const override { return Size; } Error commit() override { - *OS << StringRef((const char *)MB.base(), MB.size()); + *OS << StringRef((const char *)MB.base(), Size); return Error::success(); } private: std::unique_ptr OS; OwningMemoryBlock MB; + size_t Size; }; } // namespace @@ -114,7 +115,7 @@ auto OS = make_unique(FD, /*shouldClose=*/true, /*unbuffered=*/true); - return llvm::make_unique(Path, OS, MB); + return llvm::make_unique(Path, OS, MB, Size); } static Expected> @@ -162,7 +163,7 @@ auto OS = make_unique("-", EC, sys::fs::F_None); assert(!EC); - return llvm::make_unique("-", OS, MB); + return llvm::make_unique("-", OS, MB, Size); } unsigned Mode = fs::all_read | fs::all_write;