[PATCH] D61993: [llvm-objcopy] Add file names to error messages
Seiya Nuta via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed May 15 23:16:30 PDT 2019
seiya created this revision.
Herald added subscribers: llvm-commits, MaskRay, jakehehrlich, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a reviewer: alexshap.
Herald added a reviewer: rupprecht.
Herald added a reviewer: jhenderson.
Herald added a project: LLVM.
This patch adds the file names to llvm-objcopy error messages. It makes easy to identify which file causes an error.
Bugzilla: https://bugs.llvm.org/show_bug.cgi?id=41798
Repository:
rL LLVM
https://reviews.llvm.org/D61993
Files:
llvm/test/tools/llvm-objcopy/ELF/dynrelocsec-remove-shlink-reference.test
llvm/test/tools/llvm-objcopy/ELF/strip-section-err.test
llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
Index: llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
===================================================================
--- llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
+++ llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
@@ -157,7 +157,11 @@
template <class ELFT>
static Expected<ArrayRef<uint8_t>>
findBuildID(const object::ELFFile<ELFT> &In) {
- for (const auto &Phdr : unwrapOrError(In.program_headers())) {
+ auto PhdrsOrErr = In.program_headers();
+ if (auto Err = PhdrsOrErr.takeError())
+ return std::move(Err);
+
+ for (const auto &Phdr : *PhdrsOrErr) {
if (Phdr.p_type != PT_NOTE)
continue;
Error Err = Error::success();
@@ -681,7 +685,7 @@
StringRef SecName = SecPair.first;
StringRef File = SecPair.second;
if (Error E = dumpSectionToFile(SecName, File, Obj))
- return createFileError(Config.InputFilename, std::move(E));
+ return createFileError(File, std::move(E));
}
if (!Config.AddGnuDebugLink.empty())
@@ -730,7 +734,11 @@
ArrayRef<uint8_t> BuildIdBytes;
if (!Config.BuildIdLinkDir.empty()) {
- BuildIdBytes = unwrapOrError(findBuildID(In));
+ auto BuildIdBytesOrErr = findBuildID(In);
+ if (auto E = BuildIdBytesOrErr.takeError())
+ return createFileError(Config.InputFilename, std::move(E));
+ BuildIdBytes = *BuildIdBytesOrErr;
+
if (BuildIdBytes.size() < 2)
return createFileError(
Config.InputFilename,
@@ -742,21 +750,22 @@
if (Error E =
linkToBuildIdDir(Config, Config.InputFilename,
Config.BuildIdLinkInput.getValue(), BuildIdBytes))
- return E;
+ return createFileError(Config.InputFilename, std::move(E));
if (Error E = handleArgs(Config, *Obj, Reader, OutputElfType))
- return E;
+ return createFileError(Config.InputFilename, std::move(E));
+
std::unique_ptr<Writer> Writer =
createWriter(Config, *Obj, Out, OutputElfType);
if (Error E = Writer->finalize())
- return E;
+ return createFileError(Config.InputFilename, std::move(E));
if (Error E = Writer->write())
- return E;
+ return createFileError(Config.OutputFilename, std::move(E));
if (!Config.BuildIdLinkDir.empty() && Config.BuildIdLinkOutput)
if (Error E =
linkToBuildIdDir(Config, Config.OutputFilename,
Config.BuildIdLinkOutput.getValue(), BuildIdBytes))
- return E;
+ return createFileError(Config.OutputFilename, std::move(E));
return Error::success();
}
Index: llvm/test/tools/llvm-objcopy/ELF/strip-section-err.test
===================================================================
--- llvm/test/tools/llvm-objcopy/ELF/strip-section-err.test
+++ llvm/test/tools/llvm-objcopy/ELF/strip-section-err.test
@@ -3,7 +3,7 @@
# RUN: yaml2obj %s > %t1
# RUN: not llvm-objcopy -R .data %t1 2>&1 | FileCheck %s
-# CHECK: error: Section .data can't be removed: (.text+0x1) has relocation against symbol 'foo'
+# CHECK: error: '{{.*}}': Section .data can't be removed: (.text+0x1) has relocation against symbol 'foo'
## Check the behavior when we also remove the relocation section.
## We have no reference in this case and hence no error should be emitted.
Index: llvm/test/tools/llvm-objcopy/ELF/dynrelocsec-remove-shlink-reference.test
===================================================================
--- llvm/test/tools/llvm-objcopy/ELF/dynrelocsec-remove-shlink-reference.test
+++ llvm/test/tools/llvm-objcopy/ELF/dynrelocsec-remove-shlink-reference.test
@@ -3,7 +3,7 @@
## Check we cannot remove the .dynsym symbol table because dynamic
## relocation section .rela.dyn still references it via sh_link field.
# RUN: not llvm-objcopy -R .dynsym %t %t2 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR
-# ERR: error: Symbol table .dynsym cannot be removed because it is referenced by the relocation section .rela.dyn.
+# ERR: error: '{{.*}}': Symbol table .dynsym cannot be removed because it is referenced by the relocation section .rela.dyn.
## Check we can remove .dynsym after removing the reference.
# RUN: llvm-objcopy -R .dynsym -R .rela.dyn %t %t2
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61993.199752.patch
Type: text/x-patch
Size: 4123 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190516/5b9cfd2d/attachment.bin>
More information about the llvm-commits
mailing list