Skip to content

Commit

Permalink
Fix calcrom
Browse files Browse the repository at this point in the history
  • Loading branch information
PikalaxALT committed Dec 18, 2021
1 parent 3fd325f commit 44cd775
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
35 changes: 20 additions & 15 deletions .github/calcrom/BuildAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
string default_version("");

void BuildAnalyzer::AnalyzeObject(path fname_s) {
#ifndef NDEBUG
cerr << fname_s << endl;
#endif //NDEBUG
string ext = fname_s.extension();
SourceType sourceType = ext == ".s" ? SOURCE_ASM : SOURCE_C;
fname_s = builddir / relative(fname_s, srcbase);
Expand All @@ -25,29 +28,29 @@ void BuildAnalyzer::AnalyzeObject(path fname_s) {
if (sectionType != SECTION_OTHER) {
sizes[sectionType][sourceType] += (hdr.sh_size + 3) & ~3;
auto data = elf.ReadSectionData<unsigned>(hdr);
#ifndef NDEBUG
unordered_set<unsigned> unique_addrs;
#endif
//#ifndef NDEBUG
// unordered_set<unsigned> unique_addrs;
//#endif
for (const auto & word : data) {
if (word == 0) {
continue; // might be a relocation
}
if (find_if(program.GetProgramHeaders().cbegin(), program.GetProgramHeaders().cend(), [&word](const auto & phdr) {
return phdr.p_vaddr <= word && word < phdr.p_vaddr + phdr.p_memsz;
}) != program.GetProgramHeaders().cend()) {
#ifndef NDEBUG
unique_addrs.insert(word);
#endif
//#ifndef NDEBUG
// unique_addrs.insert(word);
//#endif
n_hardcoded++;
}
}
#ifndef NDEBUG
if (!version.empty()) {
for (const auto & word : unique_addrs) {
cerr << "hardcoded " << version << " pointer to " << hex << word << endl;
}
}
#endif
//#ifndef NDEBUG
// if (!version.empty()) {
// for (const auto & word : unique_addrs) {
// cerr << "hardcoded " << version << " pointer to " << hex << word << endl;
// }
// }
//#endif
} else if (hdr.sh_type == SHT_RELA) {
n_relocations += elf.GetSectionElementCount<Elf32_Rela>(hdr);
}
Expand Down Expand Up @@ -87,9 +90,11 @@ BuildAnalyzer &BuildAnalyzer::operator()() {
if (analyzed) {
reset();
}
string pattern = srcbase.string() + "/{src,asm,lib/{src,asm},lib/{!syscall}/{src,asm}}/*.{c,s,cpp}";
string pattern = srcbase.string() + "/{src,asm,lib/{src,asm},lib/*/{src,asm},modules/*/{asm,src}}/*.{c,s,cpp}";
for (char const * & fname : Glob(pattern, GLOB_TILDE | GLOB_BRACE | GLOB_NOSORT)) {
AnalyzeObject(fname);
if (string(fname).find("lib/syscall/") == string::npos) {
AnalyzeObject(fname);
}
}
analyzed = true;
return *this;
Expand Down
3 changes: 2 additions & 1 deletion arm9/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,9 @@ $(CXX_OBJS): $(BUILD_DIR)/%.o: %.cpp $$(dep)
$(S_OBJS) $(LIBS_OBJS): $(BUILD_DIR)/%.o: %.s $$(dep)
$(AS) $(MWASFLAGS) -o $@ $<

# Bugfix note: zsh doesn't like escapes
$(BUILD_DIR)/$(LD_TEMPLATE): $(BUILD_DIR)/%: %
(echo "KEEP_SECTION\n{\n\t.exceptix\n}\n"; cat $<) > $@
(printf "KEEP_SECTION\n{\n\t.exceptix\n}\n"; cat $<) > $@

$(BUILD_DIR)/$(LD_SCRIPT): $(LD_SPEC) $(BUILD_DIR)/$(LD_TEMPLATE)
$(MAKELCF) $(MAKELCF_FLAGS) $^ $@
Expand Down

0 comments on commit 44cd775

Please sign in to comment.