diff options
author | James Henderson <james.henderson@sony.com> | 2020-09-25 10:21:39 +0100 |
---|---|---|
committer | James Henderson <james.henderson@sony.com> | 2020-10-01 14:03:34 +0100 |
commit | a20168d0307860047ad7c8a2074f98fc25b057c2 (patch) | |
tree | eee9b302c3a52f8c6a9c3c6c8d439f8beebd18b0 /llvm/lib/Object/SymbolicFile.cpp | |
parent | 5101e7e8dd01719f9161e01e2f053c9797c247a8 (diff) | |
download | llvm-a20168d0307860047ad7c8a2074f98fc25b057c2.zip llvm-a20168d0307860047ad7c8a2074f98fc25b057c2.tar.gz llvm-a20168d0307860047ad7c8a2074f98fc25b057c2.tar.bz2 |
[Archive] Don't throw away errors for malformed archive members
When adding an archive member with a problem, e.g. a new bitcode with an
old archiver, containing an unsupported attribute, or an ELF file with a
malformed symbol table, the archiver would throw away the error and
simply add the member to the archive without any symbol entries. This
meant that the resultant archive could be silently unusable when not
using --whole-archive, and result in unexpected undefined symbols.
This change fixes this issue by addressing two FIXMEs and only throwing
away not-an-object errors. However, this meant that some LLD tests which
didn't need symbol tables and were using invalid members deliberately to
test the linker's malformed input handling no longer worked, so this
patch also stops the archiver from looking for symbols in an object if
it doesn't require a symbol table, and updates the tests accordingly.
Differential Revision: https://reviews.llvm.org/D88288
Reviewed by: grimar, rupprecht, MaskRay
Diffstat (limited to 'llvm/lib/Object/SymbolicFile.cpp')
-rw-r--r-- | llvm/lib/Object/SymbolicFile.cpp | 53 |
1 files changed, 40 insertions, 13 deletions
diff --git a/llvm/lib/Object/SymbolicFile.cpp b/llvm/lib/Object/SymbolicFile.cpp index 3db4ad9..72014fd 100644 --- a/llvm/lib/Object/SymbolicFile.cpp +++ b/llvm/lib/Object/SymbolicFile.cpp @@ -41,20 +41,14 @@ SymbolicFile::createSymbolicFile(MemoryBufferRef Object, file_magic Type, if (Type == file_magic::unknown) Type = identify_magic(Data); + if (!isSymbolicFile(Type, Context)) + return errorCodeToError(object_error::invalid_file_type); + switch (Type) { case file_magic::bitcode: - if (Context) - return IRObjectFile::create(Object, *Context); - LLVM_FALLTHROUGH; - case file_magic::unknown: - case file_magic::archive: - case file_magic::coff_cl_gl_object: - case file_magic::macho_universal_binary: - case file_magic::windows_resource: - case file_magic::pdb: - case file_magic::minidump: - case file_magic::tapi_file: - return errorCodeToError(object_error::invalid_file_type); + // Context is guaranteed to be non-null here, because bitcode magic only + // indicates a symbolic file when Context is non-null. + return IRObjectFile::create(Object, *Context); case file_magic::elf: case file_magic::elf_executable: case file_magic::elf_shared_object: @@ -95,6 +89,39 @@ SymbolicFile::createSymbolicFile(MemoryBufferRef Object, file_magic Type, MemoryBufferRef(BCData->getBuffer(), Object.getBufferIdentifier()), *Context); } + default: + llvm_unreachable("Unexpected Binary File Type"); + } +} + +bool SymbolicFile::isSymbolicFile(file_magic Type, const LLVMContext *Context) { + switch (Type) { + case file_magic::bitcode: + return Context != nullptr; + case file_magic::elf: + case file_magic::elf_executable: + case file_magic::elf_shared_object: + case file_magic::elf_core: + case file_magic::macho_executable: + case file_magic::macho_fixed_virtual_memory_shared_lib: + case file_magic::macho_core: + case file_magic::macho_preload_executable: + case file_magic::macho_dynamically_linked_shared_lib: + case file_magic::macho_dynamic_linker: + case file_magic::macho_bundle: + case file_magic::macho_dynamically_linked_shared_lib_stub: + case file_magic::macho_dsym_companion: + case file_magic::macho_kext_bundle: + case file_magic::pecoff_executable: + case file_magic::xcoff_object_32: + case file_magic::xcoff_object_64: + case file_magic::wasm_object: + case file_magic::coff_import_library: + case file_magic::elf_relocatable: + case file_magic::macho_object: + case file_magic::coff_object: + return true; + default: + return false; } - llvm_unreachable("Unexpected Binary File Type"); } |