mirror of
https://github.com/zeldaret/oot.git
synced 2025-08-10 08:50:23 +00:00
git subrepo pull --force tools/ZAPD (#727)
subrepo: subdir: "tools/ZAPD" merged: "4751db5c9" upstream: origin: "https://github.com/zeldaret/ZAPD.git" branch: "master" commit: "4751db5c9" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596"
This commit is contained in:
parent
77ec4d4916
commit
493bdbc3c6
115 changed files with 16370 additions and 2789 deletions
|
@ -1,7 +1,7 @@
|
|||
#include "ZOverlay.h"
|
||||
#include "../Directory.h"
|
||||
#include "../File.h"
|
||||
#include "../Path.h"
|
||||
#include "../Directory.h"
|
||||
#include "../StringHelper.h"
|
||||
|
||||
using namespace std;
|
||||
|
@ -20,7 +20,7 @@ ZOverlay::ZOverlay(string nName) : ZOverlay()
|
|||
|
||||
ZOverlay::~ZOverlay()
|
||||
{
|
||||
for (auto entry: entries)
|
||||
for (auto entry : entries)
|
||||
if (entry)
|
||||
delete entry;
|
||||
entries.clear();
|
||||
|
@ -33,26 +33,25 @@ ZOverlay* ZOverlay::FromBuild(string buildPath, string cfgFolderPath)
|
|||
|
||||
ZOverlay* ovl = new ZOverlay(StringHelper::Strip(cfgLines[0], "\r"));
|
||||
|
||||
vector<string> relSections = {".rel.text", ".rel.data" , ".rel.rodata"};
|
||||
vector<string> sections = {".text", ".data" , ".rodata"};
|
||||
vector<string> relSections = {".rel.text", ".rel.data", ".rel.rodata"};
|
||||
vector<string> sections = {".text", ".data", ".rodata"};
|
||||
|
||||
int sectionOffs[5] = {0};
|
||||
vector<RelocationEntry*> textRelocs;
|
||||
vector<RelocationEntry*> dataRelocs;
|
||||
vector<RelocationEntry*> rodataRelocs;
|
||||
|
||||
|
||||
// get the elf files
|
||||
vector<elfio*> readers;
|
||||
for (int i = 1; i < cfgLines.size(); i++)
|
||||
for (size_t i = 1; i < cfgLines.size(); i++)
|
||||
{
|
||||
string elfPath = buildPath + "/" + cfgLines[i].substr(0, cfgLines[i].size()-2) + ".o";
|
||||
string elfPath = buildPath + "/" + cfgLines[i].substr(0, cfgLines[i].size() - 2) + ".o";
|
||||
elfio* reader = new elfio();
|
||||
|
||||
if (!reader->load(elfPath))
|
||||
{
|
||||
// not all files were compiled
|
||||
for (auto r: readers)
|
||||
for (auto r : readers)
|
||||
delete r;
|
||||
readers.clear();
|
||||
|
||||
|
@ -66,11 +65,12 @@ ZOverlay* ZOverlay::FromBuild(string buildPath, string cfgFolderPath)
|
|||
for (auto curReader : readers)
|
||||
{
|
||||
Elf_Half sec_num = curReader->sections.size();
|
||||
for(int i = 0; i < sec_num; i++)
|
||||
for (int i = 0; i < sec_num; i++)
|
||||
{
|
||||
section* pSec = curReader->sections[i];
|
||||
|
||||
if (pSec->get_type() == SHT_REL && std::find(relSections.begin(), relSections.end(), pSec->get_name()) != relSections.end())
|
||||
if (pSec->get_type() == SHT_REL && std::find(relSections.begin(), relSections.end(),
|
||||
pSec->get_name()) != relSections.end())
|
||||
{
|
||||
SectionType sectionType = GetSectionTypeFromStr(pSec->get_name());
|
||||
|
||||
|
@ -91,16 +91,17 @@ ZOverlay* ZOverlay::FromBuild(string buildPath, string cfgFolderPath)
|
|||
string curSymName;
|
||||
Elf_Half curSymShndx = SHN_UNDEF;
|
||||
{
|
||||
symbol_section_accessor symbols(*curReader, curReader->sections[(Elf_Half)pSec->get_link()]);
|
||||
symbol_section_accessor symbols(
|
||||
*curReader, curReader->sections[(Elf_Half)pSec->get_link()]);
|
||||
Elf64_Addr value;
|
||||
Elf_Xword size;
|
||||
unsigned char bind;
|
||||
unsigned char type;
|
||||
unsigned char other;
|
||||
symbols.get_symbol(symbol, curSymName, value, size, bind, type, curSymShndx, other);
|
||||
symbols.get_symbol(symbol, curSymName, value, size, bind, type, curSymShndx,
|
||||
other);
|
||||
}
|
||||
|
||||
|
||||
// check symbols outside the elf but within the overlay
|
||||
if (curSymShndx == SHN_UNDEF)
|
||||
{
|
||||
|
@ -129,7 +130,8 @@ ZOverlay* ZOverlay::FromBuild(string buildPath, string cfgFolderPath)
|
|||
unsigned char type;
|
||||
unsigned char other;
|
||||
|
||||
symbols.get_symbol(symIdx, name, value, size, bind, type, shndx, other);
|
||||
symbols.get_symbol(symIdx, name, value, size, bind, type, shndx,
|
||||
other);
|
||||
|
||||
if (name == curSymName)
|
||||
{
|
||||
|
@ -145,7 +147,8 @@ ZOverlay* ZOverlay::FromBuild(string buildPath, string cfgFolderPath)
|
|||
RelocationType typeConverted = (RelocationType)type;
|
||||
offset += sectionOffs[sectionType];
|
||||
|
||||
RelocationEntry* reloc = new RelocationEntry(sectionType, typeConverted, offset);
|
||||
RelocationEntry* reloc =
|
||||
new RelocationEntry(sectionType, typeConverted, offset);
|
||||
|
||||
// this is to keep the correct reloc entry order
|
||||
if (sectionType == SectionType::Text)
|
||||
|
@ -163,7 +166,8 @@ ZOverlay* ZOverlay::FromBuild(string buildPath, string cfgFolderPath)
|
|||
for (int i = 0; i < sec_num; i++)
|
||||
{
|
||||
section* pSec = curReader->sections[i];
|
||||
if (pSec->get_type() == SHT_PROGBITS && std::find(sections.begin(), sections.end(), pSec->get_name()) != sections.end())
|
||||
if (pSec->get_type() == SHT_PROGBITS &&
|
||||
std::find(sections.begin(), sections.end(), pSec->get_name()) != sections.end())
|
||||
{
|
||||
SectionType sectionType = GetSectionTypeFromStr(pSec->get_name());
|
||||
sectionOffs[sectionType] += pSec->get_size();
|
||||
|
@ -178,7 +182,7 @@ ZOverlay* ZOverlay::FromBuild(string buildPath, string cfgFolderPath)
|
|||
for (auto reloc : rodataRelocs)
|
||||
ovl->entries.push_back(reloc);
|
||||
|
||||
for (auto r: readers)
|
||||
for (auto r : readers)
|
||||
delete r;
|
||||
readers.clear();
|
||||
|
||||
|
@ -198,7 +202,7 @@ string ZOverlay::GetSourceOutputCode(const std::string& prefix)
|
|||
|
||||
output += StringHelper::Sprintf(".word %i\n", entries.size());
|
||||
|
||||
for (int i = 0; i < entries.size(); i++)
|
||||
for (size_t i = 0; i < entries.size(); i++)
|
||||
{
|
||||
RelocationEntry* reloc = entries[i];
|
||||
output += StringHelper::Sprintf(".word 0x%08X\n", reloc->CalcRelocationWord());
|
||||
|
@ -227,7 +231,8 @@ SectionType ZOverlay::GetSectionTypeFromStr(string sectionName)
|
|||
return SectionType::Text;
|
||||
else if (sectionName == ".rel.data" || sectionName == ".data")
|
||||
return SectionType::Data;
|
||||
else if (sectionName == ".rel.rodata" || sectionName == ".rodata" || sectionName == ".rodata.str1.4" || sectionName == ".rodata.cst4")
|
||||
else if (sectionName == ".rel.rodata" || sectionName == ".rodata" ||
|
||||
sectionName == ".rodata.str1.4" || sectionName == ".rodata.cst4")
|
||||
return SectionType::RoData;
|
||||
else if (sectionName == ".rel.bss" || sectionName == ".bss")
|
||||
return SectionType::Bss;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue