mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-02 18:58:15 +00:00
[lld-macho] Check for arch compatibility when loading ObjFiles and TBDs
The silent failures had confused me a few times. I haven't added a similar check for platform yet as we don't yet have logic to infer the platform automatically, and so adding that check would require updating dozens of test files. Reviewed By: #lld-macho, thakis, alexshap Differential Revision: https://reviews.llvm.org/D97209
This commit is contained in:
parent
5e851733c5
commit
4752cdc9a2
@ -66,6 +66,7 @@
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
#include "llvm/Support/TarWriter.h"
|
||||
#include "llvm/TextAPI/MachO/Architecture.h"
|
||||
|
||||
using namespace llvm;
|
||||
using namespace llvm::MachO;
|
||||
@ -474,6 +475,15 @@ ObjFile::ObjFile(MemoryBufferRef mb, uint32_t modTime, StringRef archiveName)
|
||||
auto *buf = reinterpret_cast<const uint8_t *>(mb.getBufferStart());
|
||||
auto *hdr = reinterpret_cast<const mach_header_64 *>(mb.getBufferStart());
|
||||
|
||||
MachO::Architecture arch =
|
||||
MachO::getArchitectureFromCpuType(hdr->cputype, hdr->cpusubtype);
|
||||
if (arch != config->arch) {
|
||||
error(toString(this) + " has architecture " + getArchitectureName(arch) +
|
||||
" which is incompatible with target architecture " +
|
||||
getArchitectureName(config->arch));
|
||||
return;
|
||||
}
|
||||
|
||||
if (const load_command *cmd = findCommand(hdr, LC_LINKER_OPTION)) {
|
||||
auto *c = reinterpret_cast<const linker_option_command *>(cmd);
|
||||
StringRef data{reinterpret_cast<const char *>(c + 1),
|
||||
@ -672,6 +682,12 @@ DylibFile::DylibFile(const InterfaceFile &interface, DylibFile *umbrella,
|
||||
if (umbrella == nullptr)
|
||||
umbrella = this;
|
||||
|
||||
if (!interface.getArchitectures().has(config->arch)) {
|
||||
error(toString(this) + " is incompatible with " +
|
||||
getArchitectureName(config->arch));
|
||||
return;
|
||||
}
|
||||
|
||||
dylibName = saver.save(interface.getInstallName());
|
||||
compatibilityVersion = interface.getCompatibilityVersion().rawValue();
|
||||
currentVersion = interface.getCurrentVersion().rawValue();
|
||||
|
@ -1,5 +1,5 @@
|
||||
--- !tapi-tbd-v3
|
||||
archs: [ i386, x86_64 ]
|
||||
archs: [ i386, x86_64, arm64 ]
|
||||
uuids: [ 'i386: 00000000-0000-0000-0000-000000000000', 'x86_64: 00000000-0000-0000-0000-000000000001', 'arm64: 00000000-0000-0000-0000-000000000002' ]
|
||||
platform: macosx
|
||||
install-name: '/usr/lib/libc++.dylib'
|
||||
|
@ -1,10 +1,11 @@
|
||||
# REQUIRES: x86, arm
|
||||
# RUN: rm -rf %t && mkdir -p %t
|
||||
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t/test.o
|
||||
# RUN: %lld -arch x86_64 -platform_version macos 10.5.0 11.0 -o %t/x86-64-executable %t/test.o
|
||||
# RUN: %lld -arch arm64 -o %t/arm64-executable %t/test.o
|
||||
# RUN: %lld -arch x86_64 -dylib -o %t/x86-64-dylib %t/test.o
|
||||
# RUN: %lld -arch arm64 -dylib -o %t/arm64-dylib %t/test.o
|
||||
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t/x86_64-test.o
|
||||
# RUN: llvm-mc -filetype=obj -triple=arm64-apple-darwin %s -o %t/arm64-test.o
|
||||
# RUN: %lld -arch x86_64 -platform_version macos 10.5.0 11.0 -o %t/x86-64-executable %t/x86_64-test.o
|
||||
# RUN: %lld -arch arm64 -o %t/arm64-executable %t/arm64-test.o
|
||||
# RUN: %lld -arch x86_64 -dylib -o %t/x86-64-dylib %t/x86_64-test.o
|
||||
# RUN: %lld -arch arm64 -dylib -o %t/arm64-dylib %t/arm64-test.o
|
||||
|
||||
# RUN: llvm-objdump --macho --all-headers %t/x86-64-executable | FileCheck %s -DCAPS=LIB64
|
||||
# RUN: llvm-objdump --macho --all-headers %t/arm64-executable | FileCheck %s -DCAPS=0x00
|
||||
|
9
lld/test/MachO/invalid/Inputs/libincompatible.tbd
Normal file
9
lld/test/MachO/invalid/Inputs/libincompatible.tbd
Normal file
@ -0,0 +1,9 @@
|
||||
--- !tapi-tbd-v3
|
||||
archs: [ arm64 ]
|
||||
uuids: [ 'arm64: 00000000-0000-0000-0000-000000000000' ]
|
||||
platform: macosx
|
||||
install-name: '/usr/lib/libincompatible.dylib'
|
||||
current-version: 0001.001.1
|
||||
exports:
|
||||
- archs: [ 'x86_64', 'arm64' ]
|
||||
symbols: [ ]
|
9
lld/test/MachO/invalid/incompatible-arch-tapi.s
Normal file
9
lld/test/MachO/invalid/incompatible-arch-tapi.s
Normal file
@ -0,0 +1,9 @@
|
||||
# RUN: rm -rf %t; split-file %s %t
|
||||
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macosx %t/main.s -o %t/main.o
|
||||
# RUN: not %lld -arch x86_64 -lSystem %S/Inputs/libincompatible.tbd %t/main.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=ARCH
|
||||
# ARCH: error: {{.*}}libincompatible.tbd is incompatible with x86_64
|
||||
|
||||
#--- main.s
|
||||
.globl _main
|
||||
_main:
|
||||
ret
|
7
lld/test/MachO/invalid/incompatible-arch.s
Normal file
7
lld/test/MachO/invalid/incompatible-arch.s
Normal file
@ -0,0 +1,7 @@
|
||||
# RUN: llvm-mc -filetype=obj -triple=arm64-apple-darwin %s -o %t.o
|
||||
# RUN: not %lld -arch x86_64 -lSystem %t.o -o /dev/null 2>&1 | FileCheck %s -DFILE=%t.o
|
||||
# CHECK: error: {{.*}}[[FILE]] has architecture arm64 which is incompatible with target architecture x86_64
|
||||
|
||||
.globl _main
|
||||
_main:
|
||||
ret
|
Loading…
Reference in New Issue
Block a user