File tree Expand file tree Collapse file tree 2 files changed +63
-1
lines changed
Expand file tree Collapse file tree 2 files changed +63
-1
lines changed Original file line number Diff line number Diff line change @@ -1796,7 +1796,7 @@ template <class ELFT>
17961796void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
17971797 const ELFYAML::NoteSection &Section,
17981798 ContiguousBlobAccumulator &CBA) {
1799- if (!Section.Notes )
1799+ if (!Section.Notes || Section. Notes -> empty () )
18001800 return ;
18011801
18021802 unsigned Align;
@@ -1814,6 +1814,13 @@ void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
18141814 return ;
18151815 }
18161816
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+
18171824 uint64_t Offset = CBA.tell ();
18181825 for (const ELFYAML::NoteEntry &NE : *Section.Notes ) {
18191826 // Write name size.
Original file line number Diff line number Diff line change @@ -514,3 +514,58 @@ Sections:
514514 Desc : 030405
515515 - Name : GNU
516516 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: 0x{{.*}}, should be aligned to 4
522+
523+ --- !ELF
524+ FileHeader :
525+ Class : ELFCLASS32
526+ Data : ELFDATA2LSB
527+ Type : ET_EXEC
528+ Sections :
529+ - Name : .dummy
530+ Type : SHT_PROGBITS
531+ Size : 1
532+ - Name : .note
533+ Type : SHT_NOTE
534+ Notes :
535+ - Type : 0x1
536+
537+ # # Do not issue an error if the notes array is empty.
538+
539+ # RUN: yaml2obj --docnum=20 %s -o - | \
540+ # RUN: llvm-readobj --sections --section-data - | \
541+ # RUN: FileCheck %s --check-prefix=TEST20
542+
543+ # TEST20: Section {
544+ # TEST20: Name: .note
545+ # TEST20-NEXT: Type: SHT_NOTE
546+ # TEST20-NEXT: Flags [ (0x0)
547+ # TEST20-NEXT: ]
548+ # TEST20-NEXT: Address:
549+ # TEST20-NEXT: Offset:
550+ # TEST20-NEXT: Size: 0
551+ # TEST20-NEXT: Link:
552+ # TEST20-NEXT: Info:
553+ # TEST20-NEXT: AddressAlignment: 5
554+ # TEST20-NEXT: EntrySize:
555+ # TEST20-NEXT: SectionData (
556+ # TEST20-NEXT: )
557+ # TEST20-NEXT: }
558+
559+ --- !ELF
560+ FileHeader :
561+ Class : ELFCLASS32
562+ Data : ELFDATA2LSB
563+ Type : ET_EXEC
564+ Sections :
565+ - Name : .dummy
566+ Type : SHT_PROGBITS
567+ Size : 1
568+ - Name : .note
569+ Type : SHT_NOTE
570+ AddressAlign : 5
571+ Notes : []
You can’t perform that action at this time.
0 commit comments