brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.5 KiB · 39957ae Raw
114 lines · plain
1# REQUIRES: x862# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o3 4# RUN: echo "SECTIONS { \5# RUN:   .sec1 0x8000 : AT(0x8000) { sec1_start = .; *(.first_sec) sec1_end = .;} \6# RUN:   .sec2 0x8800 : AT(0x8080) { sec2_start = .; *(.second_sec) sec2_end = .;} \7# RUN: }" > %t-lma.script8# RUN: not ld.lld -o /dev/null -T %t-lma.script %t.o -shared --no-rosegment 2>&1 | FileCheck %s -check-prefix LMA-OVERLAP-ERR9# LMA-OVERLAP-ERR:      error: section .sec1 load address range overlaps with .sec210# LMA-OVERLAP-ERR-NEXT: >>> .sec1 range is [0x8000, 0x80FF]11# LMA-OVERLAP-ERR-NEXT: >>> .sec2 range is [0x8080, 0x817F]12 13# Check that we create the expected binary with --noinhibit-exec or --no-check-sections:14# RUN: ld.lld -o %t.so --script %t-lma.script %t.o -shared --no-rosegment --noinhibit-exec15# RUN: ld.lld -o %t.so --script %t-lma.script %t.o -shared --no-rosegment --no-check-sections -fatal-warnings16# RUN: ld.lld -o %t.so --script %t-lma.script %t.o -shared --no-rosegment --check-sections --no-check-sections -fatal-warnings17 18# Verify that the .sec2 was indeed placed in a PT_LOAD where the PhysAddr19# overlaps with where .sec1 is loaded:20# RUN: llvm-readelf --sections -l %t.so | FileCheck %s -check-prefix BAD-LMA21# BAD-LMA-LABEL: Section Headers:22# BAD-LMA: .sec1             PROGBITS        0000000000008000 002000 000100 00  WA  0   0  123# BAD-LMA: .sec2             PROGBITS        0000000000008800 002800 000100 00  WA  0   0  124# BAD-LMA-LABEL: Program Headers:25# BAD-LMA-NEXT:  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align26# BAD-LMA-NEXT:  LOAD           0x001000 0x0000000000000000 0x0000000000000000 0x000100 0x000100 R E 0x100027# BAD-LMA-NEXT:  LOAD           0x001100 0x0000000000000100 0x0000000000000100 0x000070 0x000070 RW  0x100028# BAD-LMA-NEXT:  LOAD           0x002000 0x0000000000008000 0x0000000000008000 0x000100 0x000100 RW  0x100029# BAD-LMA-LABEL: Section to Segment mapping:30# BAD-LMA:  01     .text .dynamic31# BAD-LMA:  02     .sec132 33# Now try a script where the virtual memory addresses overlap but ensure that the34# load addresses don't:35# RUN: echo "SECTIONS { \36# RUN:   .sec1 0x8000 : AT(0x8000) { sec1_start = .; *(.first_sec) sec1_end = .;} \37# RUN:   .sec2 0x8020 : AT(0x8800) { sec2_start = .; *(.second_sec) sec2_end = .;} \38# RUN: }" > %t-vaddr.script39# RUN: not ld.lld -o /dev/null --script %t-vaddr.script %t.o -shared 2>&1 | FileCheck %s -check-prefix VADDR-OVERLAP-ERR40# VADDR-OVERLAP-ERR:      error: section .sec1 virtual address range overlaps with .sec241# VADDR-OVERLAP-ERR-NEXT: >>> .sec1 range is [0x8000, 0x80FF]42# VADDR-OVERLAP-ERR-NEXT: >>> .sec2 range is [0x8020, 0x811F]43 44# Check that the expected binary was created with --noinhibit-exec:45# RUN: ld.lld -o %t.so --script %t-vaddr.script %t.o -shared --no-rosegment --noinhibit-exec46# RUN: llvm-readelf --sections -l %t.so | FileCheck %s -check-prefix BAD-VADDR47# BAD-VADDR-LABEL: Section Headers:48# BAD-VADDR: .sec1             PROGBITS        0000000000008000 002000 000100 00  WA  0   0  149# BAD-VADDR: .sec2             PROGBITS        0000000000008020 003020 000100 00  WA  0   0  150# BAD-VADDR-LABEL: Program Headers:51# BAD-VADDR-NEXT:  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align52# BAD-VADDR-NEXT:  LOAD           0x001000 0x0000000000000000 0x0000000000000000 0x000100 0x000100 R E 0x100053# BAD-VADDR-NEXT:  LOAD           0x001100 0x0000000000000100 0x0000000000000100 0x000070 0x000070 RW  0x100054# BAD-VADDR-NEXT:  LOAD           0x002000 0x0000000000008000 0x0000000000008000 0x000100 0x000100 RW  0x100055# BAD-VADDR-LABEL: Section to Segment mapping:56# BAD-VADDR:  01     .text .dynamic57# BAD-VADDR:  02     .sec158 59# Finally check the case where both LMA and vaddr overlap60 61# RUN: echo "SECTIONS { \62# RUN:   .sec1 0x8000 : { sec1_start = .; *(.first_sec) sec1_end = .;} \63# RUN:   .sec2 0x8040 : { sec2_start = .; *(.second_sec) sec2_end = .;} \64# RUN: }" > %t-both-overlap.script65 66# RUN: not ld.lld -o /dev/null --script %t-both-overlap.script %t.o -shared 2>&1 | FileCheck %s -check-prefix BOTH-OVERLAP-ERR67 68# BOTH-OVERLAP-ERR:      error: section .sec1 file range overlaps with .sec269# BOTH-OVERLAP-ERR-NEXT: >>> .sec1 range is [0x2000, 0x20FF]70# BOTH-OVERLAP-ERR-NEXT: >>> .sec2 range is [0x2040, 0x213F]71# BOTH-OVERLAP-ERR:      error: section .sec1 virtual address range overlaps with .sec272# BOTH-OVERLAP-ERR-NEXT: >>> .sec1 range is [0x8000, 0x80FF]73# BOTH-OVERLAP-ERR-NEXT: >>> .sec2 range is [0x8040, 0x813F]74# BOTH-OVERLAP-ERR:      error: section .sec1 load address range overlaps with .sec275# BOTH-OVERLAP-ERR-NEXT: >>> .sec1 range is [0x8000, 0x80FF]76# BOTH-OVERLAP-ERR-NEXT: >>> .sec2 range is [0x8040, 0x813F]77 78# RUN: ld.lld -o %t.so --script %t-both-overlap.script %t.o -shared --no-rosegment --noinhibit-exec79# Note: In case everything overlaps we create a binary with overlapping file80# offsets. ld.bfd seems to place .sec1 to file offset 18000 and .sec281# at 18100 so that only virtual addr and LMA overlap82# However, in order to create such a broken binary the user has to ignore a83# fatal error by passing --noinhibit-exec, so this behaviour is fine.84 85# RUN: llvm-objdump -s %t.so | FileCheck %s --check-prefix BROKEN-OUTPUT-FILE86# BROKEN-OUTPUT-FILE-LABEL: Contents of section .sec1:87# BROKEN-OUTPUT-FILE-NEXT: 8000 01010101 01010101 01010101 0101010188# BROKEN-OUTPUT-FILE-NEXT: 8010 01010101 01010101 01010101 0101010189# BROKEN-OUTPUT-FILE-NEXT: 8020 01010101 01010101 01010101 0101010190# BROKEN-OUTPUT-FILE-NEXT: 8030 01010101 01010101 01010101 0101010191## Starting here the content may be from either .sec1 or .sec2, depending on the write order.92# BROKEN-OUTPUT-FILE-NEXT: 804093 94# RUN: llvm-readelf --sections -l %t.so | FileCheck %s -check-prefix BAD-BOTH95# BAD-BOTH-LABEL: Section Headers:96# BAD-BOTH: .sec1             PROGBITS        0000000000008000 002000 000100 00  WA  0   0  197# BAD-BOTH: .sec2             PROGBITS        0000000000008040 002040 000100 00  WA  0   0  198# BAD-BOTH-LABEL: Program Headers:99# BAD-BOTH-NEXT:  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align100# BAD-BOTH-NEXT:  LOAD 0x001000 0x0000000000000000 0x0000000000000000 0x000100 0x000100 R E 0x1000101# BAD-BOTH-NEXT:  LOAD           0x001100 0x0000000000000100 0x0000000000000100 0x000070 0x000070 RW  0x1000102# BAD-BOTH-LABEL: Section to Segment mapping:103# BAD-BOTH:   01     .text .dynamic104 105.section        .first_sec,"aw",@progbits106.rept 0x100107.byte 1108.endr109 110.section        .second_sec,"aw",@progbits111.rept 0x100112.byte 2113.endr114