1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

[Object] Fix reading objects created with -fembed-bitcode-marker

Currently, this fails with many tools, e.g.

$ clang -fembed-bitcode-marker -c -o test.o test.c
$ nm test.o
nm: test.o The file was not recognized as a valid object file

-fembed-bitcode-marker creates a LLVM,bitcode section consisting of a single
byte. When reading the object file, IRObjectFile::findBitcodeInObject succeeds,
causing SymbolicFile::createSymbolicFile to try to read the "bitcode" rather
than using the outer Mach-O data - when then fails.

Fix this by making findBitcodeInObject return an error if the section size <= 1.

Patched by: Nicholas Allegra

Differential Revision: https://reviews.llvm.org/D44373

llvm-svn: 356718
This commit is contained in:
Steven Wu 2019-03-21 21:01:31 +00:00
parent 8098d943bc
commit 81b4af3e73
4 changed files with 14 additions and 0 deletions

View File

@ -78,6 +78,8 @@ IRObjectFile::findBitcodeInObject(const ObjectFile &Obj) {
StringRef SecContents;
if (std::error_code EC = Sec.getContents(SecContents))
return errorCodeToError(EC);
if (SecContents.size() <= 1)
return errorCodeToError(object_error::bitcode_section_not_found);
return MemoryBufferRef(SecContents, Obj.getFileName());
}
}

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,12 @@
# Inputs generated with:
# echo 'int hello() { return 5; }' > test.c
# clang -O -fembed-bitcode -c -o macho-bitcode-x86_64.o test.c
# clang -O -fembed-bitcode-marker -c -o macho-bitcode-marker-x86_64.o test.c
RUN: llvm-nm -a %p/Inputs/macho-bitcode-x86_64.o \
RUN: | FileCheck %s
RUN: llvm-nm -a %p/Inputs/macho-bitcode-marker-x86_64.o \
RUN: | FileCheck %s
CHECK: T _hello