diff options
Diffstat (limited to 'llvm/tools/llvm-objcopy/COFF')
-rw-r--r-- | llvm/tools/llvm-objcopy/COFF/COFFObjcopy.cpp | 10 | ||||
-rw-r--r-- | llvm/tools/llvm-objcopy/COFF/Writer.cpp | 5 |
2 files changed, 13 insertions, 2 deletions
diff --git a/llvm/tools/llvm-objcopy/COFF/COFFObjcopy.cpp b/llvm/tools/llvm-objcopy/COFF/COFFObjcopy.cpp index ea46b841bcf..6b386d29979 100644 --- a/llvm/tools/llvm-objcopy/COFF/COFFObjcopy.cpp +++ b/llvm/tools/llvm-objcopy/COFF/COFFObjcopy.cpp @@ -28,6 +28,11 @@ using namespace object; using namespace COFF; static Error handleArgs(const CopyConfig &Config, Object &Obj) { + // StripAll removes all symbols and thus also removes all relocations. + if (Config.StripAll || Config.StripAllGNU) + for (Section &Sec : Obj.Sections) + Sec.Relocs.clear(); + // If we need to do per-symbol removals, initialize the Referenced field. if (Config.StripUnneeded || Config.DiscardAll || !Config.SymbolsToRemove.empty()) @@ -36,6 +41,11 @@ static Error handleArgs(const CopyConfig &Config, Object &Obj) { // Actually do removals of symbols. Obj.removeSymbols([&](const Symbol &Sym) { + // For StripAll, all relocations have been stripped and we remove all + // symbols. + if (Config.StripAll || Config.StripAllGNU) + return true; + if (is_contained(Config.SymbolsToRemove, Sym.Name)) { // Explicitly removing a referenced symbol is an error. if (Sym.Referenced) diff --git a/llvm/tools/llvm-objcopy/COFF/Writer.cpp b/llvm/tools/llvm-objcopy/COFF/Writer.cpp index e32bf6832d9..385d43b1bae 100644 --- a/llvm/tools/llvm-objcopy/COFF/Writer.cpp +++ b/llvm/tools/llvm-objcopy/COFF/Writer.cpp @@ -46,8 +46,9 @@ void COFFWriter::layoutSections() { S.Header.PointerToRawData = FileSize; FileSize += S.Header.SizeOfRawData; // For executables, this is already // aligned to FileAlignment. - if (S.Header.NumberOfRelocations > 0) - S.Header.PointerToRelocations = FileSize; + S.Header.NumberOfRelocations = S.Relocs.size(); + S.Header.PointerToRelocations = + S.Header.NumberOfRelocations > 0 ? FileSize : 0; FileSize += S.Relocs.size() * sizeof(coff_relocation); FileSize = alignTo(FileSize, FileAlignment); |