mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-02-09 19:03:27 +00:00
[mach-o] Support data-only dylibs
In final linked shared images, the __TEXT segment contains both code and the mach-o header/load-commands. In the case of a data-only dylib, there is no code, so we need to force the addition of the __TEXT segment. llvm-svn: 220597
This commit is contained in:
parent
7c2896a234
commit
761d6549bc
@ -291,6 +291,10 @@ private:
|
||||
|
||||
collectDwarfFrameEntries(mergedFile, dwarfFrames);
|
||||
|
||||
// Skip rest of pass if no unwind info.
|
||||
if (unwindLocs.empty() && dwarfFrames.empty())
|
||||
return;
|
||||
|
||||
// FIXME: if there are more than 4 personality functions then we need to
|
||||
// defer to DWARF info for the ones we don't put in the list. They should
|
||||
// also probably be sorted by frequency.
|
||||
|
@ -500,6 +500,9 @@ void MachOFileLayout::buildFileOffsets() {
|
||||
<< ", fileOffset=" << _segInfo[&sg].fileOffset << "\n");
|
||||
|
||||
uint32_t segFileSize = 0;
|
||||
// A segment that is not zero-fill must use a least one page of disk space.
|
||||
if (sg.access)
|
||||
segFileSize = _file.pageSize;
|
||||
for (const Section *s : _segInfo[&sg].sections) {
|
||||
uint32_t sectOffset = s->address - sg.address;
|
||||
uint32_t sectFileSize =
|
||||
|
@ -394,9 +394,19 @@ void Util::organizeSections() {
|
||||
si->finalSectionIndex = sectionIndex++;
|
||||
}
|
||||
} else {
|
||||
// Main executables, need a zero-page segment
|
||||
if (_context.outputMachOType() == llvm::MachO::MH_EXECUTE)
|
||||
switch (_context.outputMachOType()){
|
||||
case llvm::MachO::MH_EXECUTE:
|
||||
// Main executables, need a zero-page segment
|
||||
segmentForName("__PAGEZERO");
|
||||
// Fall into next case.
|
||||
case llvm::MachO::MH_DYLIB:
|
||||
case llvm::MachO::MH_BUNDLE:
|
||||
// All dynamic code needs TEXT segment to hold the load commands.
|
||||
segmentForName("__TEXT");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// Group sections into segments.
|
||||
for (SectionInfo *si : _sectionInfos) {
|
||||
SegmentInfo *seg = segmentForName(si->segmentName);
|
||||
|
27
lld/test/mach-o/data-only-dylib.yaml
Normal file
27
lld/test/mach-o/data-only-dylib.yaml
Normal file
@ -0,0 +1,27 @@
|
||||
# RUN: lld -flavor darwin -arch x86_64 -dylib %s -o %t %p/Inputs/libSystem.yaml
|
||||
# RUN: llvm-nm %t | FileCheck %s
|
||||
#
|
||||
# Test that a data-only dylib can be built.
|
||||
#
|
||||
|
||||
--- !mach-o
|
||||
arch: x86_64
|
||||
file-type: MH_OBJECT
|
||||
flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ]
|
||||
sections:
|
||||
- segment: __DATA
|
||||
section: __data
|
||||
type: S_REGULAR
|
||||
attributes: [ ]
|
||||
alignment: 2
|
||||
address: 0x0000000000000000
|
||||
content: [ 0x00, 0x00, 0x00, 0x00 ]
|
||||
global-symbols:
|
||||
- name: _myData
|
||||
type: N_SECT
|
||||
scope: [ N_EXT ]
|
||||
sect: 1
|
||||
value: 0x0000000000000000
|
||||
...
|
||||
|
||||
# CHECK: _myData
|
@ -1,4 +1,4 @@
|
||||
# RUN: lld -flavor darwin -arch x86_64 %s -o %t -e start
|
||||
# RUN: lld -flavor darwin -arch x86_64 %s -o %t -e start %p/Inputs/libSystem.yaml
|
||||
# RUN: llvm-readobj -sections %t | FileCheck %s
|
||||
|
||||
# Make sure data gets put at offset
|
||||
@ -25,27 +25,6 @@ defined-atoms:
|
||||
type: data
|
||||
content: [ 01 ]
|
||||
|
||||
--- !mach-o
|
||||
arch: x86_64
|
||||
file-type: MH_DYLIB
|
||||
flags: [ ]
|
||||
install-name: /usr/lib/libSystem.B.dylib
|
||||
sections:
|
||||
- segment: __TEXT
|
||||
section: __text
|
||||
type: S_REGULAR
|
||||
attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ]
|
||||
address: 0x0000000000000000
|
||||
content: [ 0x55 ]
|
||||
|
||||
global-symbols:
|
||||
- name: dyld_stub_binder
|
||||
type: N_SECT
|
||||
scope: [ N_EXT ]
|
||||
sect: 1
|
||||
value: 0x0000000000000000
|
||||
|
||||
|
||||
|
||||
# CHECK-LABEL: Section {
|
||||
# CHECK: Name: __text
|
||||
@ -53,9 +32,6 @@ global-symbols:
|
||||
# CHECK: Size: 0x1
|
||||
# CHECK: Offset: 0
|
||||
|
||||
# CHECK-LABEL: Section {
|
||||
# CHECK: Name: __unwind_info
|
||||
|
||||
# CHECK-LABEL: Section {
|
||||
# CHECK: Name: __data
|
||||
# CHECK: Segment: __DATA
|
||||
|
@ -23,10 +23,7 @@ defined-atoms:
|
||||
# CHECK: Name: __text
|
||||
# CHECK: Segment: __TEXT
|
||||
# CHECK: Size: 0x1
|
||||
# CHECK: Offset: 4027
|
||||
|
||||
# CHECK-LABEL: Section {
|
||||
# CHECK: Name: __unwind_info
|
||||
# CHECK: Offset: 4095
|
||||
|
||||
# CHECK-LABEL: Section {
|
||||
# CHECK: Name: __data
|
||||
|
Loading…
x
Reference in New Issue
Block a user