@@ -978,12 +978,12 @@ static void setAddend(Elf_Rel_Impl<ELFT, true> &Rela, uint64_t Addend) {
978
978
}
979
979
980
980
template <class RelRange , class T >
981
- static void writeRel (const RelRange &Relocations, T *Buf) {
981
+ static void writeRel (const RelRange &Relocations, T *Buf, bool IsMips64EL ) {
982
982
for (const auto &Reloc : Relocations) {
983
983
Buf->r_offset = Reloc.Offset ;
984
984
setAddend (*Buf, Reloc.Addend );
985
985
Buf->setSymbolAndType (Reloc.RelocSymbol ? Reloc.RelocSymbol ->Index : 0 ,
986
- Reloc.Type , false );
986
+ Reloc.Type , IsMips64EL );
987
987
++Buf;
988
988
}
989
989
}
@@ -992,9 +992,11 @@ template <class ELFT>
992
992
Error ELFSectionWriter<ELFT>::visit(const RelocationSection &Sec) {
993
993
uint8_t *Buf = reinterpret_cast <uint8_t *>(Out.getBufferStart ()) + Sec.Offset ;
994
994
if (Sec.Type == SHT_REL)
995
- writeRel (Sec.Relocations , reinterpret_cast <Elf_Rel *>(Buf));
995
+ writeRel (Sec.Relocations , reinterpret_cast <Elf_Rel *>(Buf),
996
+ Sec.getObject ().IsMips64EL );
996
997
else
997
- writeRel (Sec.Relocations , reinterpret_cast <Elf_Rela *>(Buf));
998
+ writeRel (Sec.Relocations , reinterpret_cast <Elf_Rela *>(Buf),
999
+ Sec.getObject ().IsMips64EL );
998
1000
return Error::success ();
999
1001
}
1000
1002
@@ -1398,6 +1400,14 @@ Expected<std::unique_ptr<Object>> IHexELFBuilder::build() {
1398
1400
return std::move (Obj);
1399
1401
}
1400
1402
1403
+ template <class ELFT >
1404
+ ELFBuilder<ELFT>::ELFBuilder(const ELFObjectFile<ELFT> &ElfObj, Object &Obj,
1405
+ Optional<StringRef> ExtractPartition)
1406
+ : ElfFile(ElfObj.getELFFile()), Obj(Obj),
1407
+ ExtractPartition (ExtractPartition) {
1408
+ Obj.IsMips64EL = ElfFile.isMips64EL ();
1409
+ }
1410
+
1401
1411
template <class ELFT > void ELFBuilder<ELFT>::setParentSegment(Segment &Child) {
1402
1412
for (Segment &Parent : Obj.segments ()) {
1403
1413
// Every segment will overlap with itself but we don't want a segment to
@@ -1639,21 +1649,21 @@ static void getAddend(uint64_t &ToSet, const Elf_Rel_Impl<ELFT, true> &Rela) {
1639
1649
}
1640
1650
1641
1651
template <class T >
1642
- static Error initRelocations (RelocationSection *Relocs,
1643
- SymbolTableSection *SymbolTable, T RelRange) {
1652
+ static Error initRelocations (RelocationSection *Relocs, T RelRange) {
1644
1653
for (const auto &Rel : RelRange) {
1645
1654
Relocation ToAdd;
1646
1655
ToAdd.Offset = Rel.r_offset ;
1647
1656
getAddend (ToAdd.Addend , Rel);
1648
- ToAdd.Type = Rel.getType (false );
1657
+ ToAdd.Type = Rel.getType (Relocs-> getObject (). IsMips64EL );
1649
1658
1650
- if (uint32_t Sym = Rel.getSymbol (false )) {
1651
- if (!SymbolTable)
1659
+ if (uint32_t Sym = Rel.getSymbol (Relocs-> getObject (). IsMips64EL )) {
1660
+ if (!Relocs-> getObject (). SymbolTable )
1652
1661
return createStringError (
1653
1662
errc::invalid_argument,
1654
1663
" '" + Relocs->Name + " ': relocation references symbol with index " +
1655
1664
Twine (Sym) + " , but there is no symbol table" );
1656
- Expected<Symbol *> SymByIndex = SymbolTable->getSymbolByIndex (Sym);
1665
+ Expected<Symbol *> SymByIndex =
1666
+ Relocs->getObject ().SymbolTable ->getSymbolByIndex (Sym);
1657
1667
if (!SymByIndex)
1658
1668
return SymByIndex.takeError ();
1659
1669
@@ -1698,7 +1708,7 @@ Expected<SectionBase &> ELFBuilder<ELFT>::makeSection(const Elf_Shdr &Shdr) {
1698
1708
else
1699
1709
return Data.takeError ();
1700
1710
}
1701
- return Obj.addSection <RelocationSection>();
1711
+ return Obj.addSection <RelocationSection>(Obj );
1702
1712
case SHT_STRTAB:
1703
1713
// If a string table is allocated we don't want to mess with it. That would
1704
1714
// mean altering the memory image. There are no special link types or
@@ -1879,15 +1889,15 @@ template <class ELFT> Error ELFBuilder<ELFT>::readSections(bool EnsureSymtab) {
1879
1889
if (!Rels)
1880
1890
return Rels.takeError ();
1881
1891
1882
- if (Error Err = initRelocations (RelSec, Obj. SymbolTable , *Rels))
1892
+ if (Error Err = initRelocations (RelSec, *Rels))
1883
1893
return Err;
1884
1894
} else {
1885
1895
Expected<typename ELFFile<ELFT>::Elf_Rela_Range> Relas =
1886
1896
ElfFile.relas (*Shdr);
1887
1897
if (!Relas)
1888
1898
return Relas.takeError ();
1889
1899
1890
- if (Error Err = initRelocations (RelSec, Obj. SymbolTable , *Relas))
1900
+ if (Error Err = initRelocations (RelSec, *Relas))
1891
1901
return Err;
1892
1902
}
1893
1903
} else if (auto GroupSec = dyn_cast<GroupSection>(&Sec)) {
0 commit comments