Skip to content

Commit 5a59354

Browse files
committedMar 21, 2019
[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
1 parent e811333 commit 5a59354

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed
 

‎llvm/lib/Object/IRObjectFile.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ IRObjectFile::findBitcodeInObject(const ObjectFile &Obj) {
7878
StringRef SecContents;
7979
if (std::error_code EC = Sec.getContents(SecContents))
8080
return errorCodeToError(EC);
81+
if (SecContents.size() <= 1)
82+
return errorCodeToError(object_error::bitcode_section_not_found);
8183
return MemoryBufferRef(SecContents, Obj.getFileName());
8284
}
8385
}
Binary file not shown.
3.52 KB
Binary file not shown.

‎llvm/test/Object/nm-bitcode.test

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Inputs generated with:
2+
# echo 'int hello() { return 5; }' > test.c
3+
# clang -O -fembed-bitcode -c -o macho-bitcode-x86_64.o test.c
4+
# clang -O -fembed-bitcode-marker -c -o macho-bitcode-marker-x86_64.o test.c
5+
6+
RUN: llvm-nm -a %p/Inputs/macho-bitcode-x86_64.o \
7+
RUN: | FileCheck %s
8+
9+
RUN: llvm-nm -a %p/Inputs/macho-bitcode-marker-x86_64.o \
10+
RUN: | FileCheck %s
11+
12+
CHECK: T _hello

0 commit comments

Comments
 (0)