1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-11-11 03:39:59 +00:00

change section handling in mkldscript

This commit is contained in:
fig02 2022-02-11 20:33:29 -05:00
parent 7f2c5de5a7
commit 7e0b72998d

View file

@ -17,8 +17,8 @@ static void write_ld_script(FILE *fout)
int i;
int j;
fputs("SECTIONS {\n"
"/DISCARD/ : { *(.MIPS.abiflags) *(.gnu.attributes) }\n"
fputs("OUTPUT_ARCH (mips)\n\n"
"SECTIONS {\n"
" _RomSize = 0;\n"
" _RomStart = _RomSize;\n\n",
fout);
@ -61,9 +61,9 @@ static void write_ld_script(FILE *fout)
for (j = 0; j < seg->includesCount; j++)
{
fprintf(fout, " %s (.text)\n", seg->includes[j].fpath);
fprintf(fout, " . = ALIGN(0x10);\n");
if (seg->includes[j].linkerPadding != 0)
fprintf(fout, " . += 0x%X;\n", seg->includes[j].linkerPadding);
fprintf(fout, " . = ALIGN(0x10);\n");
}
fprintf(fout, " _%sSegmentTextEnd = .;\n", seg->name);
@ -74,10 +74,9 @@ static void write_ld_script(FILE *fout)
for (j = 0; j < seg->includesCount; j++)
{
if (!seg->includes[j].dataWithRodata) {
fprintf(fout, " %s (.data)\n", seg->includes[j].fpath);
fprintf(fout, " . = ALIGN(0x10);\n");
}
if (!seg->includes[j].dataWithRodata)
fprintf(fout, " %s (.data)\n"
" . = ALIGN(0x10);\n", seg->includes[j].fpath);
}
/*
@ -92,17 +91,17 @@ static void write_ld_script(FILE *fout)
fprintf(fout, " _%sSegmentDataEnd = .;\n", seg->name);
fprintf(fout, " _%sSegmentDataSize = ABSOLUTE( _%sSegmentDataEnd - _%sSegmentDataStart );\n", seg->name, seg->name, seg->name);
fprintf(fout, " _%sSegmentRoDataStart = .;\n", seg->name);
for (j = 0; j < seg->includesCount; j++)
{
if (seg->includes[j].dataWithRodata) {
fprintf(fout, " %s (.data)\n", seg->includes[j].fpath);
fprintf(fout, " . = ALIGN(0x10);\n");
}
fprintf(fout, " %s (.rodata)\n", seg->includes[j].fpath);
fprintf(fout, " . = ALIGN(0x10);\n");
if (seg->includes[j].dataWithRodata)
fprintf(fout, " %s (.data)\n"
" . = ALIGN(0x10);\n", seg->includes[j].fpath);
fprintf(fout, " %s (.rodata)\n"
" . = ALIGN(0x10);\n", seg->includes[j].fpath);
// Compilers other than IDO, such as GCC, produce different sections such as
// the ones named directly below. These sections do not contain values that
// need relocating, but we need to ensure that the base .rodata section
@ -111,16 +110,14 @@ static void write_ld_script(FILE *fout)
// the beginning of the entire rodata area in order to remain consistent.
// Inconsistencies will lead to various .rodata reloc crashes as a result of
// either missing relocs or wrong relocs.
fprintf(fout, " %s (.rodata.str1.4)\n", seg->includes[j].fpath);
fprintf(fout, " . = ALIGN(0x10);\n");
fprintf(fout, " %s (.rodata.cst4)\n", seg->includes[j].fpath);
fprintf(fout, " . = ALIGN(0x10);\n");
fprintf(fout, " %s (.rodata.cst8)\n", seg->includes[j].fpath);
fprintf(fout, " . = ALIGN(0x10);\n");
fprintf(fout, " %s (.rodata.str1.4)\n"
" . = ALIGN(0x10);\n", seg->includes[j].fpath);
fprintf(fout, " %s (.rodata.cst4)\n"
" . = ALIGN(0x10);\n", seg->includes[j].fpath);
fprintf(fout, " %s (.rodata.cst8)\n"
" . = ALIGN(0x10);\n", seg->includes[j].fpath);
}
//fprintf(fout, " . = ALIGN(0x10);\n");
fprintf(fout, " _%sSegmentRoDataEnd = .;\n", seg->name);
fprintf(fout, " _%sSegmentRoDataSize = ABSOLUTE( _%sSegmentRoDataEnd - _%sSegmentRoDataStart );\n", seg->name, seg->name, seg->name);
@ -128,9 +125,8 @@ static void write_ld_script(FILE *fout)
fprintf(fout, " _%sSegmentSDataStart = .;\n", seg->name);
for (j = 0; j < seg->includesCount; j++)
fprintf(fout, " %s (.sdata)\n", seg->includes[j].fpath);
fprintf(fout, " . = ALIGN(0x10);\n");
fprintf(fout, " %s (.sdata)\n"
" . = ALIGN(0x10);\n", seg->includes[j].fpath);
fprintf(fout, " _%sSegmentSDataEnd = .;\n", seg->name);
@ -139,16 +135,15 @@ static void write_ld_script(FILE *fout)
for (j = 0; j < seg->includesCount; j++)
fprintf(fout, " %s (.ovl)\n", seg->includes[j].fpath);
fprintf(fout, " . = ALIGN(0x10);\n");
fprintf(fout, " _%sSegmentOvlEnd = .;\n", seg->name);
if (seg->fields & (1 << STMT_increment))
fprintf(fout, " . += 0x%08X;\n", seg->increment);
// fprintf(fout, " . = ALIGN(0x%X);\n", seg->align);
fputs(" }\n", fout);
//fprintf(fout, " _RomSize += ( _%sSegmentDataEnd - _%sSegmentTextStart );\n", seg->name, seg->name);
fprintf(fout, " _RomSize += ( _%sSegmentOvlEnd - _%sSegmentTextStart );\n", seg->name, seg->name);
fprintf(fout, " _%sSegmentRomEndTemp = _RomSize;\n"
@ -166,18 +161,26 @@ static void write_ld_script(FILE *fout)
" . = ALIGN(0x10);\n"
" _%sSegmentBssStart = .;\n",
seg->name, seg->name, seg->name, seg->name);
if (seg->fields & (1 << STMT_align))
fprintf(fout, " . = ALIGN(0x%X);\n", seg->align);
for (j = 0; j < seg->includesCount; j++)
fprintf(fout, " %s (.sbss)\n", seg->includes[j].fpath);
fprintf(fout, " %s (.sbss)\n"
" . = ALIGN(0x10);\n", seg->includes[j].fpath);
for (j = 0; j < seg->includesCount; j++)
fprintf(fout, " %s (.scommon)\n", seg->includes[j].fpath);
for (j = 0; j < seg->includesCount; j++) {
fprintf(fout, " . = ALIGN(0x10);\n");
fprintf(fout, " %s (.bss)\n", seg->includes[j].fpath);
}
fprintf(fout, " %s (.scommon)\n"
" . = ALIGN(0x10);\n", seg->includes[j].fpath);
for (j = 0; j < seg->includesCount; j++)
fprintf(fout, " %s (COMMON)\n", seg->includes[j].fpath);
fprintf(fout, " %s (.bss)\n"
" . = ALIGN(0x10);\n", seg->includes[j].fpath);
for (j = 0; j < seg->includesCount; j++)
fprintf(fout, " %s (COMMON)\n"
" . = ALIGN(0x10);\n", seg->includes[j].fpath);
fprintf(fout, " . = ALIGN(0x10);\n"
" _%sSegmentBssEnd = .;\n"
" _%sSegmentEnd = .;\n"
@ -205,13 +208,55 @@ static void write_ld_script(FILE *fout)
//fprintf(fout, "\n }\n");
}
fputs(" _RomEnd = _RomSize;\n\n", fout);
fputs(" _RomEnd = _RomSize;\n}\n", fout);
// Debugging sections
fputs(
// mdebug debug sections
" .mdebug : { *(.mdebug) }" "\n"
" .mdebug.abi32 : { *(.mdebug.abi32) }" "\n"
// DWARF debug sections
// Symbols in the DWARF debugging sections are relative to the beginning of the section so we begin them at 0.
// DWARF 1
" .debug 0 : { *(.debug) }" "\n"
" .line 0 : { *(.line) }" "\n"
// GNU DWARF 1 extensions
" .debug_srcinfo 0 : { *(.debug_srcinfo) }" "\n"
" .debug_sfnames 0 : { *(.debug_sfnames) }" "\n"
// DWARF 1.1 and DWARF 2
" .debug_aranges 0 : { *(.debug_aranges) }" "\n"
" .debug_pubnames 0 : { *(.debug_pubnames) }" "\n"
// DWARF 2
" .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }" "\n"
" .debug_abbrev 0 : { *(.debug_abbrev) }" "\n"
" .debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end ) }" "\n"
" .debug_frame 0 : { *(.debug_frame) }" "\n"
" .debug_str 0 : { *(.debug_str) }" "\n"
" .debug_loc 0 : { *(.debug_loc) }" "\n"
" .debug_macinfo 0 : { *(.debug_macinfo) }" "\n"
// SGI/MIPS DWARF 2 extensions
" .debug_weaknames 0 : { *(.debug_weaknames) }" "\n"
" .debug_funcnames 0 : { *(.debug_funcnames) }" "\n"
" .debug_typenames 0 : { *(.debug_typenames) }" "\n"
" .debug_varnames 0 : { *(.debug_varnames) }" "\n"
// DWARF 3
" .debug_pubtypes 0 : { *(.debug_pubtypes) }" "\n"
" .debug_ranges 0 : { *(.debug_ranges) }" "\n"
// DWARF Extension
" .debug_macro 0 : { *(.debug_macro) }" "\n"
" .gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }" "\n", fout);
// Discard all other sections not mentioned above
fputs(" /DISCARD/ :" "\n"
" {" "\n"
" *(*);" "\n"
" }" "\n", fout);
fputs("}\n", fout);
}
static void usage(const char *execname)
{
fprintf(stderr, "Nintendo 64 linker script generation tool v0.02\n"
fprintf(stderr, "Nintendo 64 linker script generation tool v0.03\n"
"usage: %s SPEC_FILE LD_SCRIPT\n"
"SPEC_FILE file describing the organization of object files into segments\n"
"LD_SCRIPT filename of output linker script\n",
@ -239,7 +284,6 @@ int main(int argc, char **argv)
write_ld_script(ldout);
fclose(ldout);
free_rom_spec(g_segments, g_segmentsCount);
free(spec);
return 0;