@@ -339,3 +339,200 @@ Sections:
339
339
340
340
# RUN: not llvm-readobj %p/Inputs/invalid-coff-header-too-small 2>&1 | FileCheck --check-prefix=COFF-HEADER %s
341
341
# COFF-HEADER: The file was not recognized as a valid object file
342
+
343
+ ## Check that llvm-readobj reports an error if section name offset
344
+ ## overflows the section name string table.
345
+
346
+ # RUN: yaml2obj %s --docnum=17 -o %t17
347
+ # RUN: not llvm-readobj --sections %t17 2>&1 | FileCheck --check-prefix=BROKEN-SECNAME %s
348
+
349
+ ## BROKEN-SECNAME: invalid string offset
350
+
351
+ --- !ELF
352
+ FileHeader:
353
+ Class: ELFCLASS64
354
+ Data: ELFDATA2LSB
355
+ Type: ET_REL
356
+ Machine: EM_X86_64
357
+ Sections:
358
+ - Name: .shstrtab
359
+ Type: SHT_STRTAB
360
+ Size: 1
361
+
362
+ ## Check that llvm-readobj reports an error if a section has a broken offset
363
+ ## that goes past the end of the file.
364
+
365
+ # RUN: yaml2obj %s --docnum=18 -o %t18
366
+ # RUN: not llvm-readobj --sections --section-data %t18 2>&1 \
367
+ # RUN: | FileCheck --check-prefix=BROKEN-SECSHOFFSET %s
368
+
369
+ # BROKEN-SECSHOFFSET: invalid section offset
370
+
371
+ --- !ELF
372
+ FileHeader:
373
+ Class: ELFCLASS64
374
+ Data: ELFDATA2LSB
375
+ Type: ET_REL
376
+ Machine: EM_X86_64
377
+ Sections:
378
+ - Name: .foo
379
+ Type: SHT_PROGBITS
380
+ ShOffset: 0xFFFF0000
381
+
382
+ ## Check that llvm-readobj reports an error if symbol name
383
+ ## offset goes past the end of the symbol string table.
384
+
385
+ # RUN: yaml2obj %s --docnum=19 -o %t19
386
+ # RUN: not llvm-readobj --symbols %t19 2>&1 | FileCheck --check-prefix=INVALID-SYM-NAME %s
387
+
388
+ # INVALID-SYM-NAME: error: Invalid data was encountered while parsing the file
389
+
390
+ --- !ELF
391
+ FileHeader:
392
+ Class: ELFCLASS64
393
+ Data: ELFDATA2LSB
394
+ Type: ET_REL
395
+ Machine: EM_X86_64
396
+ Sections:
397
+ - Name: .strtab
398
+ Type: SHT_STRTAB
399
+ Size: 1
400
+ Symbols:
401
+ - Name: foo
402
+
403
+ ## Version index in .gnu.version overflows the version map.
404
+ ## Check llvm-readobj reports it.
405
+
406
+ # RUN: yaml2obj %s --docnum=20 -o %t20
407
+ # RUN: not llvm-readobj -dt %t20 2>&1 | FileCheck --check-prefix=INVALID-VERSION %s
408
+
409
+ # INVALID-VERSION: error: Invalid version entry
410
+
411
+ --- !ELF
412
+ FileHeader:
413
+ Class: ELFCLASS64
414
+ Data: ELFDATA2LSB
415
+ Type: ET_DYN
416
+ Machine: EM_X86_64
417
+ Sections:
418
+ - Name: .gnu.version
419
+ Type: SHT_GNU_versym
420
+ Entries: [ 0xFF ]
421
+ DynamicSymbols:
422
+ - Name: foo
423
+
424
+ ## ELF header contains e_phentsize field with a value != sizeof(Elf_Phdr).
425
+ ## Check llvm-readobj reports it.
426
+
427
+ # RUN: not llvm-readobj -l %p/Inputs/corrupt-invalid-phentsize.elf.x86-64 2>&1 \
428
+ # RUN: | FileCheck --check-prefix=PHENTSIZE %s
429
+
430
+ # PHENTSIZE: invalid e_phentsize
431
+
432
+ ## The dynamic table contains DT_STRTAB with a value that is not in any loadable segment.
433
+ ## Check llvm-readobj reports it.
434
+
435
+ # RUN: yaml2obj %s --docnum=21 -o %t21
436
+ # RUN: llvm-readobj --dynamic-table %t21 2>&1 | FileCheck --check-prefix=INVALID-DTSTRTAB %s
437
+
438
+ # INVALID-DTSTRTAB: warning: Unable to parse DT_STRTAB: Virtual address is not in any segment
439
+
440
+ --- !ELF
441
+ FileHeader:
442
+ Class: ELFCLASS64
443
+ Data: ELFDATA2LSB
444
+ Type: ET_EXEC
445
+ Machine: EM_X86_64
446
+ Sections:
447
+ - Name: .dynamic
448
+ Type: SHT_DYNAMIC
449
+ Address: 0x1000
450
+ Entries:
451
+ - Tag: DT_STRTAB
452
+ Value: 0xFFFF0000
453
+ - Tag: DT_NULL
454
+ Value: 0x0
455
+ ProgramHeaders:
456
+ - Type: PT_LOAD
457
+ VAddr: 0x1000
458
+ Sections:
459
+ - Section: .dynamic
460
+
461
+ ## Check that llvm-readobj reports an error when a dynamic relocation section
462
+ ## has sh_entsize field with size != sizeof(Elf_Rela).
463
+
464
+ # RUN: not llvm-readobj --dyn-relocations \
465
+ # RUN: %p/Inputs/corrupt-invalid-relocation-size.elf.x86-64 2>&1 \
466
+ # RUN: | FileCheck --check-prefix=RELOC-BROKEN-ENTSIZE %s
467
+
468
+ # RELOC-BROKEN-ENTSIZE: Invalid entity size
469
+
470
+ ## Check that llvm-readobj reports an error when .dynamic section has an invalid
471
+ ## size, which isn't a multiple of the dynamic entry size.
472
+
473
+ # RUN: yaml2obj %s --docnum=22 -o %t22
474
+ # RUN: not llvm-readobj --dyn-relocations %t22 2>&1 | FileCheck --check-prefix=DYN-TABLE-SIZE %s
475
+
476
+ # DYN-TABLE-SIZE: Invalid entity size
477
+
478
+ --- !ELF
479
+ FileHeader:
480
+ Class: ELFCLASS64
481
+ Data: ELFDATA2LSB
482
+ Type: ET_EXEC
483
+ Machine: EM_X86_64
484
+ Sections:
485
+ - Name: .dynamic
486
+ Type: SHT_DYNAMIC
487
+ Content: "00"
488
+
489
+ ## PT_DYNAMIC's p_offset field is so large that p_offset + p_filesz is larger
490
+ ## than the object size. Check llvm-readobj reports it.
491
+
492
+ # RUN: yaml2obj %s --docnum=23 -o %t23
493
+ # RUN: not llvm-readobj --dyn-relocations %t23 2>&1 | FileCheck --check-prefix=DYN-TABLE-PHDR %s
494
+
495
+ # DYN-TABLE-PHDR: error: PT_DYNAMIC segment offset + size exceeds the size of the file
496
+
497
+ --- !ELF
498
+ FileHeader:
499
+ Class: ELFCLASS64
500
+ Data: ELFDATA2LSB
501
+ Type: ET_EXEC
502
+ Machine: EM_X86_64
503
+ Sections:
504
+ - Name: .dynamic
505
+ Type: SHT_DYNAMIC
506
+ Entries:
507
+ - Tag: DT_NULL
508
+ Value: 0
509
+ ProgramHeaders:
510
+ - Type: PT_DYNAMIC
511
+ Offset: 0xffff0000
512
+ Sections:
513
+ - Section: .dynamic
514
+
515
+ ## PT_DYNAMIC's p_filesz field is so large that p_offset + p_filesz is larger
516
+ ## than the object size. Check llvm-readobj reports it.
517
+
518
+ # RUN: yaml2obj %s --docnum=24 -o %t24
519
+ # RUN: not llvm-readobj --dyn-relocations %t24 2>&1 \
520
+ # RUN: | FileCheck --check-prefix=DYN-TABLE-PHDR %s
521
+
522
+ --- !ELF
523
+ FileHeader:
524
+ Class: ELFCLASS64
525
+ Data: ELFDATA2LSB
526
+ Type: ET_EXEC
527
+ Machine: EM_X86_64
528
+ Sections:
529
+ - Name: .dynamic
530
+ Type: SHT_DYNAMIC
531
+ Entries:
532
+ - Tag: DT_NULL
533
+ Value: 0
534
+ ProgramHeaders:
535
+ - Type: PT_DYNAMIC
536
+ FileSize: 0xffff0000
537
+ Sections:
538
+ - Section: .dynamic
0 commit comments