File tree Expand file tree Collapse file tree 2 files changed +59
-1
lines changed Expand file tree Collapse file tree 2 files changed +59
-1
lines changed Original file line number Diff line number Diff line change @@ -1796,7 +1796,7 @@ template <class ELFT>
1796
1796
void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1797
1797
const ELFYAML::NoteSection &Section,
1798
1798
ContiguousBlobAccumulator &CBA) {
1799
- if (!Section.Notes )
1799
+ if (!Section.Notes || Section. Notes -> empty () )
1800
1800
return ;
1801
1801
1802
1802
unsigned Align;
@@ -1814,6 +1814,13 @@ void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1814
1814
return ;
1815
1815
}
1816
1816
1817
+ if (CBA.getOffset () != alignTo (CBA.getOffset (), Align)) {
1818
+ reportError (Section.Name + " : invalid offset of a note section: 0x" +
1819
+ Twine::utohexstr (CBA.getOffset ()) + " , should be aligned to " +
1820
+ Twine (Align));
1821
+ return ;
1822
+ }
1823
+
1817
1824
uint64_t Offset = CBA.tell ();
1818
1825
for (const ELFYAML::NoteEntry &NE : *Section.Notes ) {
1819
1826
// Write name size.
Original file line number Diff line number Diff line change @@ -514,3 +514,54 @@ Sections:
514
514
Desc : 030405
515
515
- Name : GNU
516
516
Type : NT_GNU_BUILD_ID
517
+
518
+ # # Check that an incorrect offset for generating notes is reported.
519
+
520
+ # RUN: not yaml2obj --docnum=19 %s 2>&1 | FileCheck %s --check-prefix=ERR_OFFSET
521
+ # ERR_OFFSET: error: .note: invalid offset of a note section: 0x501, should be aligned to 4
522
+
523
+ --- !ELF
524
+ FileHeader :
525
+ Class : ELFCLASS32
526
+ Data : ELFDATA2LSB
527
+ Type : ET_EXEC
528
+ Sections :
529
+ - Name : .note
530
+ Type : SHT_NOTE
531
+ Offset : 0x501
532
+ Notes :
533
+ - Type : 0x1
534
+
535
+ # # Do not issue an error if the notes array is empty.
536
+
537
+ # RUN: yaml2obj --docnum=20 %s -o - | \
538
+ # RUN: llvm-readobj --sections --section-data - | \
539
+ # RUN: FileCheck %s --check-prefix=TEST20
540
+
541
+ # TEST20: Section {
542
+ # TEST20: Name: .note
543
+ # TEST20-NEXT: Type: SHT_NOTE
544
+ # TEST20-NEXT: Flags [ (0x0)
545
+ # TEST20-NEXT: ]
546
+ # TEST20-NEXT: Address:
547
+ # TEST20-NEXT: Offset: 0x501
548
+ # TEST20-NEXT: Size: 0
549
+ # TEST20-NEXT: Link:
550
+ # TEST20-NEXT: Info:
551
+ # TEST20-NEXT: AddressAlignment: 5
552
+ # TEST20-NEXT: EntrySize:
553
+ # TEST20-NEXT: SectionData (
554
+ # TEST20-NEXT: )
555
+ # TEST20-NEXT: }
556
+
557
+ --- !ELF
558
+ FileHeader :
559
+ Class : ELFCLASS32
560
+ Data : ELFDATA2LSB
561
+ Type : ET_EXEC
562
+ Sections :
563
+ - Name : .note
564
+ Type : SHT_NOTE
565
+ Offset : 0x501
566
+ AddressAlign : 5
567
+ Notes : []
You can’t perform that action at this time.
0 commit comments