17
17
#include " llvm/MC/StringTableBuilder.h"
18
18
#include " llvm/Object/ELFObjectFile.h"
19
19
#include " llvm/ObjectYAML/ELFYAML.h"
20
+ #include " llvm/Support/EndianStream.h"
20
21
#include " llvm/Support/MemoryBuffer.h"
21
22
#include " llvm/Support/WithColor.h"
22
23
#include " llvm/Support/YAMLTraits.h"
@@ -549,25 +550,23 @@ template <class ELFT>
549
550
bool ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
550
551
const ELFYAML::Group &Section,
551
552
ContiguousBlobAccumulator &CBA) {
552
- typedef typename ELFT::Word Elf_Word;
553
553
assert (Section.Type == llvm::ELF::SHT_GROUP &&
554
554
" Section type is not SHT_GROUP" );
555
555
556
- SHeader.sh_entsize = sizeof (Elf_Word) ;
556
+ SHeader.sh_entsize = 4 ;
557
557
SHeader.sh_size = SHeader.sh_entsize * Section.Members .size ();
558
558
559
- auto &OS = CBA.getOSAndAlignedOffset (SHeader.sh_offset , SHeader.sh_addralign );
559
+ raw_ostream &OS =
560
+ CBA.getOSAndAlignedOffset (SHeader.sh_offset , SHeader.sh_addralign );
560
561
561
562
for (auto member : Section.Members ) {
562
- Elf_Word SIdx;
563
563
unsigned int sectionIndex = 0 ;
564
564
if (member.sectionNameOrType == " GRP_COMDAT" )
565
565
sectionIndex = llvm::ELF::GRP_COMDAT;
566
566
else if (!convertSectionIndex (SN2I, Section.Name , member.sectionNameOrType ,
567
567
sectionIndex))
568
568
return false ;
569
- SIdx = sectionIndex;
570
- OS.write ((const char *)&SIdx, sizeof (SIdx));
569
+ support::endian::write <uint32_t >(OS, sectionIndex, ELFT::TargetEndianness);
571
570
}
572
571
return true ;
573
572
}
@@ -576,17 +575,13 @@ template <class ELFT>
576
575
bool ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
577
576
const ELFYAML::SymverSection &Section,
578
577
ContiguousBlobAccumulator &CBA) {
579
- typedef typename ELFT::Half Elf_Half;
580
-
581
578
raw_ostream &OS =
582
579
CBA.getOSAndAlignedOffset (SHeader.sh_offset , SHeader.sh_addralign );
583
- for (uint16_t V : Section.Entries ) {
584
- Elf_Half Version = (Elf_Half)V;
585
- OS.write ((const char *)&Version, sizeof (Elf_Half));
586
- }
580
+ for (uint16_t V : Section.Entries )
581
+ support::endian::write <uint16_t >(OS, V, ELFT::TargetEndianness);
587
582
588
- SHeader.sh_size = Section. Entries . size () * sizeof (Elf_Half) ;
589
- SHeader.sh_entsize = sizeof (Elf_Half) ;
583
+ SHeader.sh_entsize = 2 ;
584
+ SHeader.sh_size = Section. Entries . size () * SHeader. sh_entsize ;
590
585
return true ;
591
586
}
592
587
@@ -671,22 +666,21 @@ template <class ELFT>
671
666
void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
672
667
const ELFYAML::DynamicSection &Section,
673
668
ContiguousBlobAccumulator &CBA) {
674
- typedef typename ELFT::Addr Elf_Addr;
669
+ typedef typename ELFT::uint uintX_t;
670
+
675
671
assert (Section.Type == llvm::ELF::SHT_DYNAMIC &&
676
672
" Section type is not SHT_DYNAMIC" );
677
673
678
- SHeader.sh_size = 2 * sizeof (Elf_Addr ) * Section.Entries .size ();
674
+ SHeader.sh_size = 2 * sizeof (uintX_t ) * Section.Entries .size ();
679
675
if (Section.EntSize )
680
676
SHeader.sh_entsize = *Section.EntSize ;
681
677
else
682
678
SHeader.sh_entsize = sizeof (Elf_Dyn);
683
679
684
- auto &OS = CBA.getOSAndAlignedOffset (SHeader.sh_offset , SHeader.sh_addralign );
680
+ raw_ostream &OS = CBA.getOSAndAlignedOffset (SHeader.sh_offset , SHeader.sh_addralign );
685
681
for (const ELFYAML::DynamicEntry &DE : Section.Entries ) {
686
- Elf_Addr Tag = (Elf_Addr)DE.Tag ;
687
- OS.write ((const char *)&Tag, sizeof (Elf_Addr));
688
- Elf_Addr Val = (Elf_Addr)DE.Val ;
689
- OS.write ((const char *)&Val, sizeof (Elf_Addr));
682
+ support::endian::write <uintX_t>(OS, DE.Tag , ELFT::TargetEndianness);
683
+ support::endian::write <uintX_t>(OS, DE.Val , ELFT::TargetEndianness);
690
684
}
691
685
}
692
686
0 commit comments