xref: /llvm-project/llvm/test/tools/llvm-objcopy/ELF/add-invalid-note.test (revision fb5a38bb4930736b0aab3ce428b60245921f982f)
1*fb5a38bbSserge-sans-paille## Verify that --add-section warns on invalid note sections.
2*fb5a38bbSserge-sans-paille
3*fb5a38bbSserge-sans-paille## Add [namesz, descsz, type, name, desc] for a build id.
4*fb5a38bbSserge-sans-paille
5*fb5a38bbSserge-sans-paille## Notes should be padded to 8 bytes.
6*fb5a38bbSserge-sans-paille# RUN: printf "\x04\x00\x00\x00" >  %t-miss-padding-note.bin
7*fb5a38bbSserge-sans-paille# RUN: printf "\x07\x00\x00\x00" >> %t-miss-padding-note.bin
8*fb5a38bbSserge-sans-paille# RUN: printf "\x03\x00\x00\x00" >> %t-miss-padding-note.bin
9*fb5a38bbSserge-sans-paille# RUN: printf "GNU\x00"          >> %t-miss-padding-note.bin
10*fb5a38bbSserge-sans-paille# RUN: printf "\x0c\x0d\x0e"     >> %t-miss-padding-note.bin
11*fb5a38bbSserge-sans-paille
12*fb5a38bbSserge-sans-paille## The namesz field bit is incorrect.
13*fb5a38bbSserge-sans-paille# RUN: printf "\x08\x00\x00\x00" >  %t-invalid-size-note.bin
14*fb5a38bbSserge-sans-paille# RUN: printf "\x07\x00\x00\x00" >> %t-invalid-size-note.bin
15*fb5a38bbSserge-sans-paille# RUN: printf "\x03\x00\x00\x00" >> %t-invalid-size-note.bin
16*fb5a38bbSserge-sans-paille# RUN: printf "GNU\x00"          >> %t-invalid-size-note.bin
17*fb5a38bbSserge-sans-paille# RUN: printf "\x0c\x0d\x0e\x00" >> %t-invalid-size-note.bin
18*fb5a38bbSserge-sans-paille
19*fb5a38bbSserge-sans-paille## Missing type field.
20*fb5a38bbSserge-sans-paille# RUN: printf "\x08\x00\x00\x00" >  %t-short-note.bin
21*fb5a38bbSserge-sans-paille# RUN: printf "\x07\x00\x00\x00" >> %t-short-note.bin
22*fb5a38bbSserge-sans-paille
23*fb5a38bbSserge-sans-paille# RUN: yaml2obj %s -o %t.o
24*fb5a38bbSserge-sans-paille
25*fb5a38bbSserge-sans-paille## Test each invalid note.
26*fb5a38bbSserge-sans-paille# RUN: not llvm-objcopy --add-section=.note.miss.padding=%t-miss-padding-note.bin %t.o %t-with-note.o 2>&1 | FileCheck --check-prefix=CHECK-MISS-PADDING %s
27*fb5a38bbSserge-sans-paille# CHECK-MISS-PADDING: .note.miss.padding data size must be a multiple of 4 bytes
28*fb5a38bbSserge-sans-paille
29*fb5a38bbSserge-sans-paille# RUN: not llvm-objcopy --add-section=.note.invalid.size=%t-invalid-size-note.bin %t.o %t-with-note.o 2>&1 | FileCheck --check-prefix=CHECK-INVALID-SIZE %s
30*fb5a38bbSserge-sans-paille# CHECK-INVALID-SIZE: .note.invalid.size data size is incompatible with the content of the name and description size fields: expecting 28, found 20
31*fb5a38bbSserge-sans-paille
32*fb5a38bbSserge-sans-paille# RUN: not llvm-objcopy --add-section=.note.short=%t-short-note.bin %t.o %t-with-note.o 2>&1 | FileCheck --check-prefix=CHECK-SHORT %s
33*fb5a38bbSserge-sans-paille# CHECK-SHORT: .note.short data must be either empty or at least 12 bytes long
34*fb5a38bbSserge-sans-paille
35*fb5a38bbSserge-sans-paille## Test compatibility with .note.gnu.property, which has 8-byte alignment.
36*fb5a38bbSserge-sans-paille# RUN: printf "\x04\x00\x00\x00\x40\x00\x00\x00\x05\x00\x00\x00\x47\x4e\x55\x00" >  %t-note-gnu-property.bin
37*fb5a38bbSserge-sans-paille# RUN: printf "\x02\x00\x00\xc0\x04\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00" >> %t-note-gnu-property.bin
38*fb5a38bbSserge-sans-paille# RUN: printf "\x01\x80\x01\xc0\x04\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00" >> %t-note-gnu-property.bin
39*fb5a38bbSserge-sans-paille# RUN: printf "\x01\x00\x01\xc0\x04\x00\x00\x00\x0b\x00\x00\x00\x00\x00\x00\x00" >> %t-note-gnu-property.bin
40*fb5a38bbSserge-sans-paille# RUN: printf "\x02\x00\x01\xc0\x04\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00" >> %t-note-gnu-property.bin
41*fb5a38bbSserge-sans-paille# RUN: llvm-objcopy --add-section=.note.gnu.property=%t-note-gnu-property.bin %t.o %t-with-note-gnu-property.o
42*fb5a38bbSserge-sans-paille
43*fb5a38bbSserge-sans-paille## Test that verification can be disabled.
44*fb5a38bbSserge-sans-paille# RUN: llvm-objcopy --add-section=.note.short=%t-short-note.bin --no-verify-note-sections %t.o %t-with-note.o
45*fb5a38bbSserge-sans-paille
46*fb5a38bbSserge-sans-paille## Test that last argument has precedence.
47*fb5a38bbSserge-sans-paille# RUN: llvm-objcopy --add-section=.note.short=%t-short-note.bin --verify-note-sections --no-verify-note-sections %t.o %t-with-note.o
48*fb5a38bbSserge-sans-paille# RUN: not llvm-objcopy --add-section=.note.short=%t-short-note.bin --no-verify-note-sections --verify-note-sections %t.o %t-with-note.o 2>&1 | FileCheck --check-prefix=CHECK-SHORT %s
49*fb5a38bbSserge-sans-paille
50*fb5a38bbSserge-sans-paille!ELF
51*fb5a38bbSserge-sans-pailleFileHeader:
52*fb5a38bbSserge-sans-paille  Class:           ELFCLASS64
53*fb5a38bbSserge-sans-paille  Data:            ELFDATA2LSB
54*fb5a38bbSserge-sans-paille  Type:            ET_REL
55