xref: /llvm-project/llvm/test/tools/llvm-objcopy/ELF/parent-loop-check.test (revision a7a447be0fa934505f0c423fb97b91a68c1cc715)
16e4dc6f2SAlexander Shaposhnikov# This test has a subtle purpose. Because of the specifics of the layout
26e4dc6f2SAlexander Shaposhnikov# algorithm if we're not careful cycles can occur when we resolve the order
36e4dc6f2SAlexander Shaposhnikov# that we should layout segments in. In this test we're making sure that the
46e4dc6f2SAlexander Shaposhnikov# PT_LOAD segment won't set the PT_NOTE segment as the first to be laid out
56e4dc6f2SAlexander Shaposhnikov# while the PT_NOTE segment sets the PT_LOAD load to be the first to be laid
66e4dc6f2SAlexander Shaposhnikov# out. This problem becomes visible if the layout of the file changes due to
76e4dc6f2SAlexander Shaposhnikov# the removal of a section. We use -O binary here because removing a section
86e4dc6f2SAlexander Shaposhnikov# in this way won't cause the location of the PT_LOAD segment to change if we
96e4dc6f2SAlexander Shaposhnikov# don't.
106e4dc6f2SAlexander Shaposhnikov
116e4dc6f2SAlexander Shaposhnikov# RUN: yaml2obj %s -o %t
126e4dc6f2SAlexander Shaposhnikov# RUN: llvm-objcopy -R .note -O binary %t %t2
136e4dc6f2SAlexander Shaposhnikov# RUN: od -Ax -t x1 %t2 | FileCheck %s
146e4dc6f2SAlexander Shaposhnikov
156e4dc6f2SAlexander Shaposhnikov!ELF
166e4dc6f2SAlexander ShaposhnikovFileHeader:
176e4dc6f2SAlexander Shaposhnikov  Class:           ELFCLASS64
186e4dc6f2SAlexander Shaposhnikov  Data:            ELFDATA2LSB
196e4dc6f2SAlexander Shaposhnikov  Type:            ET_EXEC
206e4dc6f2SAlexander Shaposhnikov  Machine:         EM_X86_64
216e4dc6f2SAlexander ShaposhnikovSections:
226e4dc6f2SAlexander Shaposhnikov  - Name:            .note
236e4dc6f2SAlexander Shaposhnikov    Type:            SHT_PROGBITS
246e4dc6f2SAlexander Shaposhnikov    Flags:           [ SHF_ALLOC ]
256e4dc6f2SAlexander Shaposhnikov    Address:         0x1000
266e4dc6f2SAlexander Shaposhnikov    AddressAlign:    0x1000
276e4dc6f2SAlexander Shaposhnikov    Content:         "32323232"
286e4dc6f2SAlexander Shaposhnikov    Size:            32
296e4dc6f2SAlexander Shaposhnikov  - Name:            .rodata
306e4dc6f2SAlexander Shaposhnikov    Flags:           [ SHF_ALLOC ]
316e4dc6f2SAlexander Shaposhnikov    Type:            SHT_PROGBITS
326e4dc6f2SAlexander Shaposhnikov    Address:         0x1020
336e4dc6f2SAlexander Shaposhnikov    Size:            4064
346e4dc6f2SAlexander Shaposhnikov    Content:         "DEADBEEF"
356e4dc6f2SAlexander ShaposhnikovProgramHeaders:
366e4dc6f2SAlexander Shaposhnikov  - Type:     PT_LOAD
376e4dc6f2SAlexander Shaposhnikov    Flags:    [ PF_R ]
386e4dc6f2SAlexander Shaposhnikov    VAddr:    0x1000
39*a7a447beSGeorgii Rymar    FirstSec: .note
40*a7a447beSGeorgii Rymar    LastSec:  .rodata
416e4dc6f2SAlexander Shaposhnikov  - Type:     PT_NOTE
426e4dc6f2SAlexander Shaposhnikov    Flags:    [ PF_R ]
436e4dc6f2SAlexander Shaposhnikov    VAddr:    0x1000
44*a7a447beSGeorgii Rymar    FirstSec: .note
45*a7a447beSGeorgii Rymar    LastSec:  .note
466e4dc6f2SAlexander Shaposhnikov
476e4dc6f2SAlexander Shaposhnikov# CHECK: 000000 de ad be ef
48