Skip to content

Commit a6db7cf

Browse files
author
Georgii Rymar
committed
[llvm-readelf/obj] - Index phdrs and relocations from 0 when reporting warnings.
As was mentioned in comments here: https://reviews.llvm.org/D92636#inline-864967 we are not consistent and sometimes index things from 0, but sometimes from 1 in warnings. This patch fixes 2 places: messages reported for program headers and messages reported for relocations. Differential revision: https://reviews.llvm.org/D93805
1 parent 8ea72b3 commit a6db7cf

File tree

6 files changed

+37
-38
lines changed

6 files changed

+37
-38
lines changed

llvm/test/tools/llvm-readobj/ELF/gnu-notes.test

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,15 @@ Sections:
172172

173173
# ERR3-GNU: Displaying notes found at file offset 0xffff0000 with length 0x00000000:
174174
# ERR3-GNU-NEXT: Owner Data size Description
175-
# ERR3-GNU-NEXT: warning: '[[FILE]]': unable to read notes from the PT_NOTE segment with index 1: invalid offset (0xffff0000) or size (0x0)
175+
# ERR3-GNU-NEXT: warning: '[[FILE]]': unable to read notes from the PT_NOTE segment with index 0: invalid offset (0xffff0000) or size (0x0)
176176
# ERR3-GNU-NOT: {{.}}
177177

178178
# ERR3-LLVM: Notes [
179179
# ERR3-LLVM-NEXT: NoteSection {
180180
# ERR3-LLVM-NEXT: Name: <?>
181181
# ERR3-LLVM-NEXT: Offset: 0xFFFF0000
182182
# ERR3-LLVM-NEXT: Size: 0x0
183-
# ERR3-LLVM-NEXT: warning: '[[FILE]]': unable to read notes from the PT_NOTE segment with index 1: invalid offset (0xffff0000) or size (0x0)
183+
# ERR3-LLVM-NEXT: warning: '[[FILE]]': unable to read notes from the PT_NOTE segment with index 0: invalid offset (0xffff0000) or size (0x0)
184184
# ERR3-LLVM-NEXT: }
185185
# ERR3-LLVM-NEXT: ]
186186

@@ -203,15 +203,15 @@ ProgramHeaders:
203203

204204
# ERR4-GNU: Displaying notes found at file offset 0x00000000 with length 0xffff0000:
205205
# ERR4-GNU-NEXT: Owner Data size Description
206-
# ERR4-GNU-NEXT: warning: '[[FILE]]': unable to read notes from the PT_NOTE segment with index 1: invalid offset (0x0) or size (0xffff0000)
206+
# ERR4-GNU-NEXT: warning: '[[FILE]]': unable to read notes from the PT_NOTE segment with index 0: invalid offset (0x0) or size (0xffff0000)
207207
# ERR4-GNU-NOT: {{.}}
208208

209209
# ERR4-LLVM: Notes [
210210
# ERR4-LLVM-NEXT: NoteSection {
211211
# ERR4-LLVM-NEXT: Name: <?>
212212
# ERR4-LLVM-NEXT: Offset: 0x0
213213
# ERR4-LLVM-NEXT: Size: 0xFFFF0000
214-
# ERR4-LLVM-NEXT: warning: '[[FILE]]': unable to read notes from the PT_NOTE segment with index 1: invalid offset (0x0) or size (0xffff0000)
214+
# ERR4-LLVM-NEXT: warning: '[[FILE]]': unable to read notes from the PT_NOTE segment with index 0: invalid offset (0x0) or size (0xffff0000)
215215
# ERR4-LLVM-NEXT: }
216216
# ERR4-LLVM-NEXT: ]
217217

llvm/test/tools/llvm-readobj/ELF/note-core-ntfile-bad.test

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# RUN: llvm-readelf -n %t1.o 2>&1 | FileCheck -DFILE=%t1.o %s --check-prefix=ERR-HEADER-SHORT
1212
# RUN: llvm-readobj -n %t1.o 2>&1 | FileCheck -DFILE=%t1.o %s --check-prefix=ERR-HEADER-SHORT
1313

14-
# ERR-HEADER-SHORT: warning: '[[FILE]]': unable to read note with index 0 from the PT_NOTE segment with index 1: the note of size 0x8 is too short, expected at least 0x10
14+
# ERR-HEADER-SHORT: warning: '[[FILE]]': unable to read note with index 0 from the PT_NOTE segment with index 0: the note of size 0x8 is too short, expected at least 0x10
1515

1616
# .section ".note.foo", "a"
1717
# .align 4
@@ -42,7 +42,7 @@ ProgramHeaders:
4242
# RUN: llvm-readelf -n %t2.o 2>&1 | FileCheck -DFILE=%t2.o %s --check-prefix=ERR-NULL-TERM
4343
# RUN: llvm-readobj -n %t2.o 2>&1 | FileCheck -DFILE=%t2.o %s --check-prefix=ERR-NULL-TERM
4444

45-
# ERR-NULL-TERM: warning: '[[FILE]]': unable to read note with index 0 from the PT_NOTE segment with index 1: the note is not NUL terminated
45+
# ERR-NULL-TERM: warning: '[[FILE]]': unable to read note with index 0 from the PT_NOTE segment with index 0: the note is not NUL terminated
4646

4747
# .section ".note.foo", "a"
4848
# .align 4
@@ -78,7 +78,7 @@ ProgramHeaders:
7878
# RUN: llvm-readelf -n %t3.o 2>&1 | FileCheck -DFILE=%t3.o %s --check-prefix=ERR-FILE-COUNT
7979
# RUN: llvm-readobj -n %t3.o 2>&1 | FileCheck -DFILE=%t3.o %s --check-prefix=ERR-FILE-COUNT
8080

81-
# ERR-FILE-COUNT: warning: '[[FILE]]': unable to read note with index 0 from the PT_NOTE segment with index 1: unable to read file mappings (found 2): the note of size 0x2c is too short
81+
# ERR-FILE-COUNT: warning: '[[FILE]]': unable to read note with index 0 from the PT_NOTE segment with index 0: unable to read file mappings (found 2): the note of size 0x2c is too short
8282

8383
# .section ".note.foo", "a"
8484
# .align 4
@@ -114,7 +114,7 @@ ProgramHeaders:
114114
# RUN: llvm-readelf -n %t4.o 2>&1 | FileCheck -DFILE=%t4.o %s --check-prefix=ERR-FILE-END-EARLY
115115
# RUN: llvm-readobj -n %t4.o 2>&1 | FileCheck -DFILE=%t4.o %s --check-prefix=ERR-FILE-END-EARLY
116116

117-
# ERR-FILE-END-EARLY: warning: '[[FILE]]': unable to read note with index 0 from the PT_NOTE segment with index 1: unable to read the file name for the mapping with index 2: the note of size 0x44 is truncated
117+
# ERR-FILE-END-EARLY: warning: '[[FILE]]': unable to read note with index 0 from the PT_NOTE segment with index 0: unable to read the file name for the mapping with index 2: the note of size 0x44 is truncated
118118

119119
# .section ".note.foo", "a"
120120
# .align 4

llvm/test/tools/llvm-readobj/ELF/relocation-errors.test

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
# LLVM: Relocations [
88
# LLVM-NEXT: Section (3) .rel.text {
9+
# LLVM-NEXT: warning: '[[FILE]]': unable to print relocation 0 in SHT_REL section with index 3: unable to read an entry with index 4278124286 from SHT_SYMTAB section with index 6: can't read an entry at 0x17e7e7e7d0: it goes past the end of the section (0x90)
910
# LLVM-NEXT: warning: '[[FILE]]': unable to print relocation 1 in SHT_REL section with index 3: unable to read an entry with index 4278124286 from SHT_SYMTAB section with index 6: can't read an entry at 0x17e7e7e7d0: it goes past the end of the section (0x90)
10-
# LLVM-NEXT: warning: '[[FILE]]': unable to print relocation 2 in SHT_REL section with index 3: unable to read an entry with index 4278124286 from SHT_SYMTAB section with index 6: can't read an entry at 0x17e7e7e7d0: it goes past the end of the section (0x90)
1111
# LLVM-NEXT: 0x2 R_X86_64_NONE -{{$}}
1212
# LLVM-NEXT: 0x3 R_X86_64_NONE .sec.symbol1{{$}}
1313
# LLVM-NEXT: warning: '[[FILE]]': invalid section index: 255
@@ -17,14 +17,14 @@
1717
# LLVM-NEXT: 0x6 R_X86_64_NONE <section 2>{{$}}
1818
# LLVM-NEXT: }
1919
# LLVM-NEXT: Section (4) .rela.text {
20-
# LLVM-NEXT: warning: '[[FILE]]': unable to print relocation 1 in SHT_RELA section with index 4: invalid sh_type for symbol table, expected SHT_SYMTAB or SHT_DYNSYM
20+
# LLVM-NEXT: warning: '[[FILE]]': unable to print relocation 0 in SHT_RELA section with index 4: invalid sh_type for symbol table, expected SHT_SYMTAB or SHT_DYNSYM
2121
# LLVM-NEXT: }
2222
# LLVM-NEXT: ]
2323

2424
# GNU: Relocation section '.rel.text' at offset 0x41 contains 7 entries:
2525
# GNU-NEXT: Offset Info Type Symbol's Value Symbol's Name
26+
# GNU-NEXT: warning: '[[FILE]]': unable to print relocation 0 in SHT_REL section with index 3: unable to read an entry with index 4278124286 from SHT_SYMTAB section with index 6: can't read an entry at 0x17e7e7e7d0: it goes past the end of the section (0x90)
2627
# GNU-NEXT: warning: '[[FILE]]': unable to print relocation 1 in SHT_REL section with index 3: unable to read an entry with index 4278124286 from SHT_SYMTAB section with index 6: can't read an entry at 0x17e7e7e7d0: it goes past the end of the section (0x90)
27-
# GNU-NEXT: warning: '[[FILE]]': unable to print relocation 2 in SHT_REL section with index 3: unable to read an entry with index 4278124286 from SHT_SYMTAB section with index 6: can't read an entry at 0x17e7e7e7d0: it goes past the end of the section (0x90)
2828
# GNU-NEXT: 0000000000000002 0000000000000000 R_X86_64_NONE
2929
# GNU-NEXT: 0000000000000003 0000000200000000 R_X86_64_NONE 0000000000000000 .sec.symbol1
3030
# GNU-NEXT: warning: '[[FILE]]': invalid section index: 255
@@ -35,7 +35,7 @@
3535
# GNU-EMPTY:
3636
# GNU-NEXT: Relocation section '.rela.text' at offset 0xb1 contains 1 entries:
3737
# GNU-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
38-
# GNU-NEXT: warning: '[[FILE]]': unable to print relocation 1 in SHT_RELA section with index 4: invalid sh_type for symbol table, expected SHT_SYMTAB or SHT_DYNSYM
38+
# GNU-NEXT: warning: '[[FILE]]': unable to print relocation 0 in SHT_RELA section with index 4: invalid sh_type for symbol table, expected SHT_SYMTAB or SHT_DYNSYM
3939

4040
--- !ELF
4141
FileHeader:

llvm/test/tools/llvm-readobj/ELF/relocations.test

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -510,15 +510,15 @@ Symbols:
510510

511511
# LLVM-SYMNDX: Relocations [
512512
# LLVM-SYMNDX-NEXT: Section (1) .rela.text {
513-
# LLVM-SYMNDX-NEXT: warning: '[[FILE]]': unable to print relocation 1 in SHT_RELA section with index 1: unable to read an entry with index 2 from SHT_SYMTAB section with index 2: can't read an entry at 0x30: it goes past the end of the section (0x30)
514-
# LLVM-SYMNDX-NEXT: warning: '[[FILE]]': unable to print relocation 2 in SHT_RELA section with index 1: unable to read an entry with index 3 from SHT_SYMTAB section with index 2: can't read an entry at 0x48: it goes past the end of the section (0x30)
513+
# LLVM-SYMNDX-NEXT: warning: '[[FILE]]': unable to print relocation 0 in SHT_RELA section with index 1: unable to read an entry with index 2 from SHT_SYMTAB section with index 2: can't read an entry at 0x30: it goes past the end of the section (0x30)
514+
# LLVM-SYMNDX-NEXT: warning: '[[FILE]]': unable to print relocation 1 in SHT_RELA section with index 1: unable to read an entry with index 3 from SHT_SYMTAB section with index 2: can't read an entry at 0x48: it goes past the end of the section (0x30)
515515
# LLVM-SYMNDX-NEXT: }
516516
# LLVM-SYMNDX-NEXT: ]
517517

518518
# GNU-SYMNDX: Relocation section '.rela.text' at offset 0x40 contains 2 entries:
519519
# GNU-SYMNDX-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
520-
# GNU-SYMNDX-NEXT: warning: '[[FILE]]': unable to print relocation 1 in SHT_RELA section with index 1: unable to read an entry with index 2 from SHT_SYMTAB section with index 2: can't read an entry at 0x30: it goes past the end of the section (0x30)
521-
# GNU-SYMNDX-NEXT: warning: '[[FILE]]': unable to print relocation 2 in SHT_RELA section with index 1: unable to read an entry with index 3 from SHT_SYMTAB section with index 2: can't read an entry at 0x48: it goes past the end of the section (0x30)
520+
# GNU-SYMNDX-NEXT: warning: '[[FILE]]': unable to print relocation 0 in SHT_RELA section with index 1: unable to read an entry with index 2 from SHT_SYMTAB section with index 2: can't read an entry at 0x30: it goes past the end of the section (0x30)
521+
# GNU-SYMNDX-NEXT: warning: '[[FILE]]': unable to print relocation 1 in SHT_RELA section with index 1: unable to read an entry with index 3 from SHT_SYMTAB section with index 2: can't read an entry at 0x48: it goes past the end of the section (0x30)
522522

523523
--- !ELF
524524
FileHeader:

0 commit comments

Comments
 (0)