brintos

brintos / llvm-project-archived public Read only

0
0
Text · 9.5 KiB · 6eb5357 Raw
309 lines · plain
1## The computed LMA of a section in a PT_LOAD equals sh_offset-p_offset+p_paddr.2## The byte offset difference between two sections equals the difference between their LMAs.3 4## Corollary: if two sections are in the same PT_LOAD, the byte offset5## difference equals the difference between their sh_addr fields.6 7# RUN: yaml2obj --docnum=1 %s -o %t18# RUN: llvm-objcopy -O binary %t1 %t1.out9# RUN: od -A x -t x2 %t1.out | FileCheck %s --check-prefix=CHECK1 --ignore-case10# RUN: wc -c %t1.out | FileCheck %s --check-prefix=SIZE111 12# CHECK1:      000000 c3c3 c3c3 0000 0000 0000 0000 0000 000013# CHECK1-NEXT: 000010 0000 0000 0000 0000 0000 0000 0000 000014# CHECK1-NEXT: *15# CHECK1-NEXT: 001000 323216# SIZE1:       409817 18--- !ELF19FileHeader:20  Class:           ELFCLASS6421  Data:            ELFDATA2LSB22  Type:            ET_EXEC23  Machine:         EM_X86_6424Sections:25  - Name:            .text26    Type:            SHT_PROGBITS27    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]28    Address:         0x100029    AddressAlign:    0x100030    Content:         "c3c3c3c3"31  - Name:            .data32    Type:            SHT_PROGBITS33    Flags:           [ SHF_ALLOC, SHF_WRITE ]34    Address:         0x200035    AddressAlign:    0x100036    Content:         "3232"37ProgramHeaders:38  - Type:     PT_LOAD39    Flags:    [ PF_R, PF_W ]40    FirstSec: .text41    LastSec:  .data42 43## The computed LMA of a section not in a PT_LOAD equals its sh_addr.44 45# RUN: yaml2obj --docnum=2 %s -o %t246# RUN: llvm-objcopy -O binary %t2 %t2.out47# RUN: od -A x -t x2 %t2.out | FileCheck %s --check-prefix=CHECK2 --ignore-case48# RUN: wc -c %t2.out | FileCheck %s --check-prefix=SIZE249 50## The computed LMA of .data is 0x4000. The minimum LMA of all non-empty sections is 0x1000.51## The content of .data will be written at 0x4000-0x1000 = 0x3000.52# CHECK2:      000000 c3c3 c3c3 0000 0000 0000 0000 0000 000053# CHECK2-NEXT: 000010 0000 0000 0000 0000 0000 0000 0000 000054# CHECK2-NEXT: *55# CHECK2-NEXT: 003000 323256# SIZE2:       1229057 58--- !ELF59FileHeader:60  Class:           ELFCLASS6461  Data:            ELFDATA2LSB62  Type:            ET_EXEC63  Machine:         EM_X86_6464Sections:65  - Name:            .text66    Type:            SHT_PROGBITS67    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]68    ## Not in a PT_LOAD. LMA = sh_addr = 0x1000.69    Address:         0x100070    AddressAlign:    0x100071    Content:         "c3c3c3c3"72  - Name:            .data73    Type:            SHT_PROGBITS74    Flags:           [ SHF_ALLOC, SHF_WRITE ]75    ## LMA = sh_offset-p_offset+p_paddr = 0x2000-0x2000+0x4000 = 0x4000.76    Address:         0x200077    AddressAlign:    0x100078    Content:         "3232"79ProgramHeaders:80  - Type:     PT_LOAD81    Flags:    [ PF_R, PF_W ]82    VAddr:    0x200083    ## p_vaddr is increased from 0x2000 to 0x4000.84    PAddr:    0x400085    FirstSec: .data86    LastSec:  .data87 88## Check that we use sh_offset instead of sh_addr to decide where to write section contents.89 90# RUN: yaml2obj --docnum=3 %s -o %t391# RUN: llvm-objcopy -O binary %t3 %t3.out92# RUN: od -A x -t x2 %t3.out | FileCheck %s --check-prefix=CHECK3 --ignore-case93# RUN: wc -c %t3.out | FileCheck %s --check-prefix=SIZE394 95## The minimum LMA of all non-empty sections is 0x1000.96## The content of .data will be written at 0x3000-0x1000 = 0x2000.97# CHECK3:      000000 c3c3 c3c3 0000 0000 0000 0000 0000 000098# CHECK3-NEXT: 000010 0000 0000 0000 0000 0000 0000 0000 000099# CHECK3-NEXT: *100# CHECK3-NEXT: 002000 3232101# SIZE3:       8194102 103--- !ELF104FileHeader:105  Class:           ELFCLASS64106  Data:            ELFDATA2LSB107  Type:            ET_EXEC108  Machine:         EM_X86_64109Sections:110  - Name:            .text111    Type:            SHT_PROGBITS112    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]113    ## Not in a PT_LOAD. LMA = sh_addr = 0x1000.114    Address:         0x1000115    AddressAlign:    0x1000116    Content:         "c3c3c3c3"117  - Name:            .data118    Type:            SHT_PROGBITS119    Flags:           [ SHF_ALLOC, SHF_WRITE ]120    ## sh_addr is increased from 0x2000 to 0x3000, but it is ignored.121    ## LMA = sh_offset-p_offset+p_paddr = 0x2000-0x2000+0x3000 = 0x3000.122    Address:         0x3000123    AddressAlign:    0x1000124    Content:         "3232"125ProgramHeaders:126  - Type:     PT_LOAD127    Flags:    [ PF_R, PF_W ]128    VAddr:    0x3000129    FirstSec: .data130    LastSec:  .data131 132## The first section (.text) is empty. Test that we skip its LMA until the first133## non-empty section, otherwise we would leave a large number of leading zeroes.134# RUN: yaml2obj --docnum=4 %s -o %t4135# RUN: llvm-objcopy -O binary %t4 %t4.out136# RUN: od -A x -t x2 %t4.out | FileCheck %s --check-prefix=SKIPEMPTY137 138# SKIPEMPTY:      000000 3232139# SKIPEMPTY-NEXT: 000002140 141--- !ELF142FileHeader:143  Class:   ELFCLASS64144  Data:    ELFDATA2LSB145  Type:    ET_EXEC146  Machine: EM_X86_64147Sections:148  - Name:         .text149    Type:         SHT_PROGBITS150    Flags:        [ SHF_ALLOC, SHF_EXECINSTR ]151    Address:      0x1000152    AddressAlign: 0x1000153  - Name:         gap154    Type:         Fill155    Size:         0x1000156  - Name:         .data157    Type:         SHT_PROGBITS158    Flags:        [ SHF_ALLOC, SHF_WRITE ]159    Content:      "3232"160 161## The last section (.data) is empty. Test that we stop dumping after the last162## non-empty section, otherwise we would leave a large number of trailing zeroes.163# RUN: yaml2obj --docnum=5 %s -o %t5164# RUN: llvm-objcopy -O binary %t5 %t5.out165# RUN: od -A x -t x2 %t5.out | FileCheck %s --check-prefix=SKIPEMPTY166 167--- !ELF168FileHeader:169  Class:   ELFCLASS64170  Data:    ELFDATA2LSB171  Type:    ET_EXEC172  Machine: EM_X86_64173Sections:174  - Name:         .text175    Type:         SHT_PROGBITS176    Flags:        [ SHF_ALLOC, SHF_EXECINSTR ]177    Address:      0x1000178    AddressAlign: 0x1000179    Content:      "3232"180  - Name:         gap181    Type:         Fill182    Size:         0xffd183  - Name:         .data184    Type:         SHT_PROGBITS185    Flags:        [ SHF_ALLOC, SHF_WRITE ]186 187## NOBITS sections should not appear in output.188# RUN: yaml2obj --docnum=6 %s -o %t6189# RUN: llvm-objcopy -O binary %t6 %t6.out190# RUN: od -A x -t x2 %t6.out | FileCheck %s --check-prefix=SKIPNOBITS --ignore-case191 192# SKIPNOBITS:      000000 c3c3 c3c3193# SKIPNOBITS-NEXT: 000004194 195--- !ELF196FileHeader:197  Class:   ELFCLASS64198  Data:    ELFDATA2LSB199  Type:    ET_EXEC200  Machine: EM_X86_64201Sections:202  - Name:         .bss203    Type:         SHT_NOBITS204    Flags:        [ SHF_ALLOC ]205    Address:      0x1000206    AddressAlign: 0x1000207    Size:         0x123208  - Name:         gap209    Type:         Fill210    Size:         0xffd211  - Name:         .text212    Type:         SHT_PROGBITS213    Flags:        [ SHF_ALLOC, SHF_EXECINSTR ]214    Address:      0x4000215    AddressAlign: 0x1000216    Content:      "c3c3c3c3"217 218## If .bss is converted to non-SHT_NOBITS, align its new offset. This may affect219## the output size.220# RUN: yaml2obj --docnum=7 %s -o %t7221# RUN: llvm-objcopy -O binary --set-section-flags .bss=alloc,contents %t7 %t7.out222# RUN: od -A x -t x2 %t7.out | FileCheck %s --check-prefix=FILLNOBITS --ignore-case223 224# FILLNOBITS:      000000 c3c3 0000 0000 0000 0000 0000 0000 0000225# FILLNOBITS-NEXT: 000010 0000 00226# FILLNOBITS-NEXT: 000013227 228--- !ELF229FileHeader:230  Class:   ELFCLASS64231  Data:    ELFDATA2LSB232  Type:    ET_EXEC233  Machine: EM_X86_64234Sections:235  - Name:         .text236    Type:         SHT_PROGBITS237    Flags:        [ SHF_ALLOC, SHF_EXECINSTR ]238    Address:      0x1000239    AddressAlign: 0x1000240    Content:      "c3c3"241  - Name:         .bss242    Type:         SHT_NOBITS243    Flags:        [ SHF_ALLOC ]244    ## sh_offset is not aligned.245    ShOffset:     0x1002246    Size:         0x3247    AddressAlign: 0x10248ProgramHeaders:249  - Type:     PT_LOAD250    Flags:    [ PF_R, PF_W, PF_X ]251    Offset:   0x1000252    VAddr:    0x1000253    PAddr:    0x1000254    FileSize: 0x2255    MemSize:  0x13256    Align:    0x1000257 258## Test that sections do not move relative to their physical addresses if259## the physical address is not aligned. This behavior matches GNU objcopy260## and is important for embedded images where the physical address is261## used to store the initial data image. Without converting the type of a262## NOBITS section, don't align the offset. This matches GNU objcopy when263## the physical address of a section is not aligned.264 265# RUN: yaml2obj --docnum=8 %s -o %t8266# RUN: llvm-objcopy -O binary --only-section=.text --only-section=.data %t8 %t8.out267# RUN: od -A x -t x1 %t8.out | FileCheck %s --check-prefix=PHYSUNALIGNED --ignore-case268 269# PHYSUNALIGNED:      000000 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff 00270# PHYSUNALIGNED-NEXT: 000010 11 22 33 44 bd ac cd ab271 272--- !ELF273FileHeader:274  Class:           ELFCLASS64275  Data:            ELFDATA2LSB276  Type:            ET_EXEC277  Machine:         EM_X86_64278ProgramHeaders:279  - Type:            PT_LOAD280    Flags:           [ PF_X, PF_R ]281    FirstSec:        .text282    LastSec:         .text283    VAddr:           0x200000284    PAddr:           0x200000285    Align:           0x1000286  - Type:            PT_LOAD287    Flags:           [ PF_W, PF_R ]288    FirstSec:        .data289    LastSec:         .data290    VAddr:           0x400000291    PAddr:           0x200014292## PAddr is not aligned by sh_addralign(.data)293    Align:           0x1000294Sections:295  - Name:            .text296    Type:            SHT_PROGBITS297    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]298    Address:         0x200000299    AddressAlign:    0x1300    Offset:          0x1000301    Content:         112233445566778899aabbccddeeff0011223344302  - Name:            .data303    Type:            SHT_PROGBITS304    Flags:           [ SHF_WRITE, SHF_ALLOC ]305    Address:         0x400000306    AddressAlign:    0x8307    Offset:          0x2000308    Content:         BDACCDAB309