The -n (--nmagic) disables page alignment, and acts as a -Bstatic The -N (--omagic) does what -n does but also marks the executable segment as writeable. As page alignment is disabled headers are not allocated unless explicit in the linker script. To disable page alignment in LLD we choose to set the page sizes to 1 so that any alignment based on the page size does nothing. To set the Target->PageSize to 1 we implement -z common-page-size, which has the side effect of allowing the user to set the value as well. Setting the page alignments to 1 does mean that any use of CONSTANT(MAXPAGESIZE) or CONSTANT(COMMONPAGESIZE) in a linker script will return 1, unlike in ld.bfd. However given that -n and -N disable paging these probably shouldn't be used in a linker script where -n or -N is in use. Differential Revision: https://reviews.llvm.org/D61688 llvm-svn: 360593
86 lines
2.5 KiB
Plaintext
86 lines
2.5 KiB
Plaintext
# REQUIRES: x86
|
|
|
|
# Test that mimics a use case of -n to produce a kernel mapped shared-object
|
|
# in a non paged context. We specifically want to test:
|
|
# - We can allocate the headers into the first program header (via PHDRS)
|
|
# typically -n does not allocate headers.
|
|
# - The alignment of the .text section is not page aligned.
|
|
|
|
# RUN: echo ".text; .globl foo; foo: nop" > %t.s
|
|
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %t.s -o %t.o
|
|
# RUN: ld.lld %t.o -o %t.so --shared --hash-style=sysv --script %s
|
|
# RUN: llvm-readobj --program-headers %t.so | FileCheck %s
|
|
# RUN: ld.lld %t.o -o %t2.so --shared --hash-style=sysv -n --script %s
|
|
# RUN: llvm-readobj --program-headers %t2.so | FileCheck %s --check-prefix=CHECK-N
|
|
|
|
SECTIONS {
|
|
. = 0x0 + SIZEOF_HEADERS;
|
|
.hash : { *(.hash) } :text
|
|
.dynsym : { *(.dynsym) }
|
|
.dynstr : { *(.dynstr) }
|
|
. = ALIGN(4);
|
|
.text : { *(.text*) }
|
|
.dynamic : { *(.dynamic) } :text :dynamic
|
|
}
|
|
|
|
PHDRS {
|
|
text PT_LOAD FLAGS(5) FILEHDR PHDRS;
|
|
dynamic PT_DYNAMIC FLAGS(4);
|
|
}
|
|
|
|
# CHECK: ProgramHeaders [
|
|
# CHECK-NEXT: ProgramHeader {
|
|
# CHECK-NEXT: Type: PT_LOAD
|
|
# CHECK-NEXT: Offset: 0x0
|
|
# CHECK-NEXT: VirtualAddress: 0x0
|
|
# CHECK-NEXT: PhysicalAddress: 0x0
|
|
# CHECK-NEXT: FileSize:
|
|
# CHECK-NEXT: MemSize:
|
|
# CHECK-NEXT: Flags [
|
|
# CHECK-NEXT: PF_R
|
|
# CHECK-NEXT: PF_X
|
|
# CHECK-NEXT: ]
|
|
# CHECK-NEXT: Alignment: 4096
|
|
# CHECK-NEXT: }
|
|
# CHECK-NEXT: ProgramHeader {
|
|
# CHECK-NEXT: Type: PT_DYNAMIC
|
|
# CHECK-NEXT: Offset: 0x108
|
|
# CHECK-NEXT: VirtualAddress: 0x108
|
|
# CHECK-NEXT: PhysicalAddress: 0x108
|
|
# CHECK-NEXT: FileSize:
|
|
# CHECK-NEXT: MemSize:
|
|
# CHECK-NEXT: Flags [
|
|
# CHECK-NEXT: PF_R
|
|
# CHECK-NEXT: ]
|
|
# CHECK-NEXT: Alignment: 8
|
|
# CHECK-NEXT: }
|
|
# CHECK-NEXT: ]
|
|
|
|
# CHECK-N: ProgramHeaders [
|
|
# CHECK-N-NEXT: ProgramHeader {
|
|
# CHECK-N-NEXT: Type: PT_LOAD
|
|
# CHECK-N-NEXT: Offset: 0x0
|
|
# CHECK-N-NEXT: VirtualAddress: 0x0
|
|
# CHECK-N-NEXT: PhysicalAddress: 0x0
|
|
# CHECK-N-NEXT: FileSize: 360
|
|
# CHECK-N-NEXT: MemSize: 360
|
|
# CHECK-N-NEXT: Flags [
|
|
# CHECK-N-NEXT: PF_R
|
|
# CHECK-N-NEXT: PF_X
|
|
# CHECK-N-NEXT: ]
|
|
# CHECK-N-NEXT: Alignment: 8
|
|
# CHECK-N-NEXT: }
|
|
# CHECK-N-NEXT: ProgramHeader {
|
|
# CHECK-N-NEXT: Type: PT_DYNAMIC
|
|
# CHECK-N-NEXT: Offset: 0x108
|
|
# CHECK-N-NEXT: VirtualAddress: 0x108
|
|
# CHECK-N-NEXT: PhysicalAddress: 0x108
|
|
# CHECK-N-NEXT: FileSize:
|
|
# CHECK-N-NEXT: MemSize:
|
|
# CHECK-N-NEXT: Flags [
|
|
# CHECK-N-NEXT: PF_R
|
|
# CHECK-N-NEXT: ]
|
|
# CHECK-N-NEXT: Alignment: 8
|
|
# CHECK-N-NEXT: }
|
|
# CHECK-N-NEXT: ]
|