2020-07-31 05:29:14 +08:00
|
|
|
# REQUIRES: x86
|
[lld-macho] Ensure segments are laid out contiguously
codesign/libstuff checks that the `__LLVM` segment is directly
before `__LINKEDIT` by checking that `fileOff + fileSize == next segment
fileOff`. Previously, there would be gaps between the segments due to
the fact that their fileOffs are page-aligned but their fileSizes
aren't. In order to satisfy codesign, we page-align fileOff *before*
calculating fileSize. (I don't think codesign checks for the relative
ordering of other segments, so in theory we could do this just for
`__LLVM`, but ld64 seems to do it for all segments.)
Note that we *don't* round up the fileSize of the `__LINKEDIT` segment.
Since it's the last segment, it doesn't need to worry about contiguity;
in addition, codesign checks that the last (hidden) section in
`__LINKEDIT` covers the last byte of the segment, so if we rounded up
`__LINKEDIT`'s size we would have to do the same for its last section,
which is a bother.
While at it, I also addressed a FIXME in the linkedit-contiguity.s test
to cover more `__LINKEDIT` sections.
Reviewed By: #lld-macho, thakis, alexshap
Differential Revision: https://reviews.llvm.org/D100848
2021-04-21 04:58:07 +08:00
|
|
|
# RUN: rm -rf %t; split-file %s %t
|
2020-07-31 05:29:14 +08:00
|
|
|
|
|
|
|
## codesign requires that each setion in __LINKEDIT ends where the next one
|
|
|
|
## starts. This test enforces that invariant.
|
[lld-macho] Ensure segments are laid out contiguously
codesign/libstuff checks that the `__LLVM` segment is directly
before `__LINKEDIT` by checking that `fileOff + fileSize == next segment
fileOff`. Previously, there would be gaps between the segments due to
the fact that their fileOffs are page-aligned but their fileSizes
aren't. In order to satisfy codesign, we page-align fileOff *before*
calculating fileSize. (I don't think codesign checks for the relative
ordering of other segments, so in theory we could do this just for
`__LLVM`, but ld64 seems to do it for all segments.)
Note that we *don't* round up the fileSize of the `__LINKEDIT` segment.
Since it's the last segment, it doesn't need to worry about contiguity;
in addition, codesign checks that the last (hidden) section in
`__LINKEDIT` covers the last byte of the segment, so if we rounded up
`__LINKEDIT`'s size we would have to do the same for its last section,
which is a bother.
While at it, I also addressed a FIXME in the linkedit-contiguity.s test
to cover more `__LINKEDIT` sections.
Reviewed By: #lld-macho, thakis, alexshap
Differential Revision: https://reviews.llvm.org/D100848
2021-04-21 04:58:07 +08:00
|
|
|
## It also checks that the last section in __LINKEDIT covers the last byte of
|
|
|
|
## the segment.
|
2020-07-31 05:29:14 +08:00
|
|
|
|
[lld-macho] Ensure segments are laid out contiguously
codesign/libstuff checks that the `__LLVM` segment is directly
before `__LINKEDIT` by checking that `fileOff + fileSize == next segment
fileOff`. Previously, there would be gaps between the segments due to
the fact that their fileOffs are page-aligned but their fileSizes
aren't. In order to satisfy codesign, we page-align fileOff *before*
calculating fileSize. (I don't think codesign checks for the relative
ordering of other segments, so in theory we could do this just for
`__LLVM`, but ld64 seems to do it for all segments.)
Note that we *don't* round up the fileSize of the `__LINKEDIT` segment.
Since it's the last segment, it doesn't need to worry about contiguity;
in addition, codesign checks that the last (hidden) section in
`__LINKEDIT` covers the last byte of the segment, so if we rounded up
`__LINKEDIT`'s size we would have to do the same for its last section,
which is a bother.
While at it, I also addressed a FIXME in the linkedit-contiguity.s test
to cover more `__LINKEDIT` sections.
Reviewed By: #lld-macho, thakis, alexshap
Differential Revision: https://reviews.llvm.org/D100848
2021-04-21 04:58:07 +08:00
|
|
|
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/foo.s -o %t/foo.o
|
|
|
|
# RUN: %lld %t/foo.o -dylib -o %t/libfoo.dylib
|
|
|
|
|
|
|
|
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/test.s -o %t/test.o
|
2021-11-04 12:01:49 +08:00
|
|
|
# RUN: %lld -lSystem -adhoc_codesign -o %t/test %t/libfoo.dylib %t/test.o
|
2020-07-31 05:29:14 +08:00
|
|
|
|
|
|
|
# RUN: llvm-objdump --macho --all-headers %t/test | FileCheck %s
|
|
|
|
|
[lld-macho] Ensure segments are laid out contiguously
codesign/libstuff checks that the `__LLVM` segment is directly
before `__LINKEDIT` by checking that `fileOff + fileSize == next segment
fileOff`. Previously, there would be gaps between the segments due to
the fact that their fileOffs are page-aligned but their fileSizes
aren't. In order to satisfy codesign, we page-align fileOff *before*
calculating fileSize. (I don't think codesign checks for the relative
ordering of other segments, so in theory we could do this just for
`__LLVM`, but ld64 seems to do it for all segments.)
Note that we *don't* round up the fileSize of the `__LINKEDIT` segment.
Since it's the last segment, it doesn't need to worry about contiguity;
in addition, codesign checks that the last (hidden) section in
`__LINKEDIT` covers the last byte of the segment, so if we rounded up
`__LINKEDIT`'s size we would have to do the same for its last section,
which is a bother.
While at it, I also addressed a FIXME in the linkedit-contiguity.s test
to cover more `__LINKEDIT` sections.
Reviewed By: #lld-macho, thakis, alexshap
Differential Revision: https://reviews.llvm.org/D100848
2021-04-21 04:58:07 +08:00
|
|
|
# CHECK: segname __LINKEDIT
|
|
|
|
# CHECK-NEXT: vmaddr
|
|
|
|
# CHECK-NEXT: vmsize
|
|
|
|
# CHECK-NEXT: fileoff [[#LINKEDIT_OFF:]]
|
|
|
|
# CHECK-NEXT: filesize [[#LINKEDIT_SIZE:]]
|
|
|
|
|
2020-07-31 05:29:14 +08:00
|
|
|
# CHECK: cmd LC_DYLD_INFO_ONLY
|
|
|
|
# CHECK-NEXT: cmdsize 48
|
[lld-macho] Ensure segments are laid out contiguously
codesign/libstuff checks that the `__LLVM` segment is directly
before `__LINKEDIT` by checking that `fileOff + fileSize == next segment
fileOff`. Previously, there would be gaps between the segments due to
the fact that their fileOffs are page-aligned but their fileSizes
aren't. In order to satisfy codesign, we page-align fileOff *before*
calculating fileSize. (I don't think codesign checks for the relative
ordering of other segments, so in theory we could do this just for
`__LLVM`, but ld64 seems to do it for all segments.)
Note that we *don't* round up the fileSize of the `__LINKEDIT` segment.
Since it's the last segment, it doesn't need to worry about contiguity;
in addition, codesign checks that the last (hidden) section in
`__LINKEDIT` covers the last byte of the segment, so if we rounded up
`__LINKEDIT`'s size we would have to do the same for its last section,
which is a bother.
While at it, I also addressed a FIXME in the linkedit-contiguity.s test
to cover more `__LINKEDIT` sections.
Reviewed By: #lld-macho, thakis, alexshap
Differential Revision: https://reviews.llvm.org/D100848
2021-04-21 04:58:07 +08:00
|
|
|
# CHECK-NEXT: rebase_off [[#REBASE_OFF:]]
|
|
|
|
# CHECK-NEXT: rebase_size [[#REBASE_SIZE:]]
|
|
|
|
# CHECK-NEXT: bind_off [[#BIND_OFF: REBASE_OFF + REBASE_SIZE]]
|
2020-07-31 05:29:14 +08:00
|
|
|
# CHECK-NEXT: bind_size [[#BIND_SIZE:]]
|
[lld-macho] Ensure segments are laid out contiguously
codesign/libstuff checks that the `__LLVM` segment is directly
before `__LINKEDIT` by checking that `fileOff + fileSize == next segment
fileOff`. Previously, there would be gaps between the segments due to
the fact that their fileOffs are page-aligned but their fileSizes
aren't. In order to satisfy codesign, we page-align fileOff *before*
calculating fileSize. (I don't think codesign checks for the relative
ordering of other segments, so in theory we could do this just for
`__LLVM`, but ld64 seems to do it for all segments.)
Note that we *don't* round up the fileSize of the `__LINKEDIT` segment.
Since it's the last segment, it doesn't need to worry about contiguity;
in addition, codesign checks that the last (hidden) section in
`__LINKEDIT` covers the last byte of the segment, so if we rounded up
`__LINKEDIT`'s size we would have to do the same for its last section,
which is a bother.
While at it, I also addressed a FIXME in the linkedit-contiguity.s test
to cover more `__LINKEDIT` sections.
Reviewed By: #lld-macho, thakis, alexshap
Differential Revision: https://reviews.llvm.org/D100848
2021-04-21 04:58:07 +08:00
|
|
|
# CHECK-NEXT: weak_bind_off [[#WEAK_OFF: BIND_OFF + BIND_SIZE]]
|
|
|
|
# CHECK-NEXT: weak_bind_size [[#WEAK_SIZE:]]
|
|
|
|
# CHECK-NEXT: lazy_bind_off [[#LAZY_OFF: WEAK_OFF + WEAK_SIZE]]
|
2020-07-31 05:29:14 +08:00
|
|
|
# CHECK-NEXT: lazy_bind_size [[#LAZY_SIZE:]]
|
|
|
|
# CHECK-NEXT: export_off [[#EXPORT_OFF: LAZY_OFF + LAZY_SIZE]]
|
2021-03-16 02:54:18 +08:00
|
|
|
# CHECK-NEXT: export_size [[#EXPORT_SIZE:]]
|
|
|
|
|
|
|
|
# CHECK: cmd LC_FUNCTION_STARTS
|
|
|
|
# CHECK-NEXT: cmdsize
|
|
|
|
# CHECK-NEXT: dataoff [[#FUNCSTARTS_OFF: EXPORT_OFF + EXPORT_SIZE]]
|
2021-06-17 03:23:07 +08:00
|
|
|
# CHECK-NEXT: datasize [[#FUNCSTARTS_SIZE:]]
|
|
|
|
|
|
|
|
# CHECK: cmd LC_DATA_IN_CODE
|
|
|
|
# CHECK-NEXT: cmdsize
|
|
|
|
# CHECK-NEXT: dataoff [[#DIC_OFF: FUNCSTARTS_OFF + FUNCSTARTS_SIZE]]
|
2020-07-31 05:29:14 +08:00
|
|
|
|
[lld-macho] Ensure segments are laid out contiguously
codesign/libstuff checks that the `__LLVM` segment is directly
before `__LINKEDIT` by checking that `fileOff + fileSize == next segment
fileOff`. Previously, there would be gaps between the segments due to
the fact that their fileOffs are page-aligned but their fileSizes
aren't. In order to satisfy codesign, we page-align fileOff *before*
calculating fileSize. (I don't think codesign checks for the relative
ordering of other segments, so in theory we could do this just for
`__LLVM`, but ld64 seems to do it for all segments.)
Note that we *don't* round up the fileSize of the `__LINKEDIT` segment.
Since it's the last segment, it doesn't need to worry about contiguity;
in addition, codesign checks that the last (hidden) section in
`__LINKEDIT` covers the last byte of the segment, so if we rounded up
`__LINKEDIT`'s size we would have to do the same for its last section,
which is a bother.
While at it, I also addressed a FIXME in the linkedit-contiguity.s test
to cover more `__LINKEDIT` sections.
Reviewed By: #lld-macho, thakis, alexshap
Differential Revision: https://reviews.llvm.org/D100848
2021-04-21 04:58:07 +08:00
|
|
|
# CHECK: cmd LC_CODE_SIGNATURE
|
|
|
|
# CHECK-NEXT: cmdsize 16
|
|
|
|
# CHECK-NEXT: dataoff [[#SIG_OFF:]]
|
|
|
|
# CHECK-NEXT: datasize [[#SIG_SIZE: LINKEDIT_OFF + LINKEDIT_SIZE - SIG_OFF]]
|
|
|
|
|
|
|
|
#--- foo.s
|
|
|
|
.globl _foo, _weak_foo
|
|
|
|
.weak_definition _weak_foo
|
|
|
|
_foo:
|
|
|
|
_weak_foo:
|
|
|
|
|
|
|
|
#--- test.s
|
2020-07-31 05:29:14 +08:00
|
|
|
.globl _main
|
|
|
|
_main:
|
[lld-macho] Ensure segments are laid out contiguously
codesign/libstuff checks that the `__LLVM` segment is directly
before `__LINKEDIT` by checking that `fileOff + fileSize == next segment
fileOff`. Previously, there would be gaps between the segments due to
the fact that their fileOffs are page-aligned but their fileSizes
aren't. In order to satisfy codesign, we page-align fileOff *before*
calculating fileSize. (I don't think codesign checks for the relative
ordering of other segments, so in theory we could do this just for
`__LLVM`, but ld64 seems to do it for all segments.)
Note that we *don't* round up the fileSize of the `__LINKEDIT` segment.
Since it's the last segment, it doesn't need to worry about contiguity;
in addition, codesign checks that the last (hidden) section in
`__LINKEDIT` covers the last byte of the segment, so if we rounded up
`__LINKEDIT`'s size we would have to do the same for its last section,
which is a bother.
While at it, I also addressed a FIXME in the linkedit-contiguity.s test
to cover more `__LINKEDIT` sections.
Reviewed By: #lld-macho, thakis, alexshap
Differential Revision: https://reviews.llvm.org/D100848
2021-04-21 04:58:07 +08:00
|
|
|
callq _foo
|
|
|
|
callq _weak_foo
|
2020-07-31 05:29:14 +08:00
|
|
|
ret
|
2021-06-17 03:23:07 +08:00
|
|
|
|
|
|
|
.p2align 2, 0x90
|
|
|
|
.data_region jt32
|
|
|
|
.long 0
|
|
|
|
.end_data_region
|