Skip to content

Commit dccb61d

Browse files
authored
Merge pull request #521 from uyjulian/srxfixup_u
Changes to use ELF toolchain for IOP
2 parents 44935d2 + 00f199a commit dccb61d

23 files changed

+9857
-109
lines changed

Defs.make

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ EE_PKG_CONFIG ?= $(EE_TOOL_PREFIX)pkg-config
3030
# Defintions for the IOP toolchain.
3131
#
3232

33-
IOP_TOOL_PREFIX ?= mipsel-ps2-irx-
33+
IOP_TOOL_PREFIX ?= mipsel-none-elf-
3434
IOP_CC ?= $(IOP_TOOL_PREFIX)gcc
3535
IOP_AS ?= $(IOP_TOOL_PREFIX)as
3636
IOP_LD ?= $(IOP_TOOL_PREFIX)ld

iop/Rules.make

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ ifeq ($(DEBUG),1)
4040
IOP_CFLAGS += -DDEBUG
4141
endif
4242
# Linker flags
43-
IOP_LDFLAGS := -nostdlib -s $(IOP_LDFLAGS)
43+
IOP_LDFLAGS := -nostdlib -dc -r $(IOP_LDFLAGS)
4444

4545
# Additional C compiler flags for GCC >=v5.3.0
4646
# -msoft-float is to "remind" GCC/Binutils that the soft-float ABI is to be used. This is due to a bug, which
@@ -69,8 +69,17 @@ endif
6969
# Assembler flags
7070
IOP_ASFLAGS := $(ASFLAGS_TARGET) -EL -G0 $(IOP_ASFLAGS)
7171

72+
# Default link file
73+
ifeq ($(IOP_LINKFILE),)
74+
IOP_LINKFILE := $(PS2SDKSRC)/iop/startup/src/linkfile
75+
endif
76+
7277
IOP_OBJS := $(IOP_OBJS:%=$(IOP_OBJS_DIR)%)
7378

79+
IOP_BIN_ELF := $(IOP_BIN:.irx=.notiopmod.elf)
80+
81+
IOP_BIN_STRIPPED_ELF := $(IOP_BIN:.irx=.notiopmod.stripped.elf)
82+
7483
# Externally defined variables: IOP_BIN, IOP_OBJS, IOP_LIB
7584

7685
# These macros can be used to simplify certain build rules.
@@ -95,6 +104,9 @@ $(IOP_OBJS_DIR)%.o: $(IOP_SRC_DIR)%.s
95104

96105
.INTERMEDIATE:: $(IOP_LIB)_tmp$(MAKE_CURPID) $(IOP_OBJS_DIR)build-imports.c $(IOP_OBJS_DIR)build-exports.c
97106

107+
$(PS2SDKSRC)/tools/srxfixup/bin/srxfixup: $(PS2SDKSRC)/tools/srxfixup
108+
$(MAKEREC) $<
109+
98110
$(IOP_OBJS_DIR)template-imports.h:
99111
$(DIR_GUARD)
100112
$(PRINTF) '%s\n' "#include \"irx_imports.h\"" > $@
@@ -121,9 +133,16 @@ $(IOP_OBJS_DIR)exports.o: $(IOP_OBJS_DIR)build-exports.c
121133
$(DIR_GUARD)
122134
$(IOP_C_COMPILE) $(IOP_IETABLE_CFLAGS) -c $< -o $@
123135

124-
$(IOP_BIN): $(IOP_OBJS) $(IOP_LIB_ARCHIVES) $(IOP_ADDITIONAL_DEPS)
136+
$(IOP_BIN_ELF): $(IOP_OBJS) $(IOP_LIB_ARCHIVES) $(IOP_ADDITIONAL_DEPS)
137+
$(DIR_GUARD)
138+
$(IOP_C_COMPILE) -T$(IOP_LINKFILE) $(IOP_OPTFLAGS) -o $@ $(IOP_OBJS) $(IOP_LDFLAGS) $(IOP_LIB_ARCHIVES) $(IOP_LIBS)
139+
140+
$(IOP_BIN_STRIPPED_ELF): $(IOP_BIN_ELF)
125141
$(DIR_GUARD)
126-
$(IOP_C_COMPILE) $(IOP_OPTFLAGS) -o $(IOP_BIN) $(IOP_OBJS) $(IOP_LDFLAGS) $(IOP_LIB_ARCHIVES) $(IOP_LIBS)
142+
$(IOP_STRIP) --strip-unneeded --remove-section=.pdr --remove-section=.comment --remove-section=.mdebug.abi32 --remove-section=.gnu.attributes -o $@ $<
143+
144+
$(IOP_BIN): $(IOP_BIN_STRIPPED_ELF) $(PS2SDKSRC)/tools/srxfixup/bin/srxfixup
145+
$(PS2SDKSRC)/tools/srxfixup/bin/srxfixup --irx1 -o $@ $<
127146

128147
$(IOP_LIB)_tmp$(MAKE_CURPID): $(IOP_OBJS)
129148
$(DIR_GUARD)

iop/startup/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ release:
2424
@$(PRINTF) 'Installing %slinkfile into %s/iop/startup\n' $(IOP_SRC_DIR) $(PS2SDK)
2525
$(ECHO) Installing $(IOP_SRC_DIR)linkfile into $(PS2SDK)/iop/startup
2626
cp -f $(IOP_SRC_DIR)linkfile $(PS2SDK)/iop/startup
27-
@$(ECHO) Installing $(IOP_OBJS_DIR)crt0.o into $(PS2DEV)/ee/mipsel-ps2-irx/lib
28-
cp -f $(IOP_OBJS_DIR)crt0.o $(PS2DEV)/iop/mipsel-ps2-irx/lib
27+
@$(ECHO) Installing $(IOP_OBJS_DIR)crt0.o into $(PS2DEV)/iop/mipsel-none-elf/lib
28+
cp -f $(IOP_OBJS_DIR)crt0.o $(PS2DEV)/iop/mipsel-none-elf/lib

iop/startup/src/linkfile

Lines changed: 145 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -3,110 +3,158 @@
33
# ____| | ____| | | |____|
44
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
55
#-----------------------------------------------------------------------
6-
# Copyright 2001-2022, ps2dev - http://www.ps2dev.org
6+
# Copyright ps2dev - http://www.ps2dev.org
77
# Licenced under Academic Free License version 2.0
88
# Review ps2sdk README & LICENSE files for further details.
99
#
1010
# Linkfile script for iop-ld
1111
*/
1212

13-
OUTPUT_FORMAT("elf32-littlemips")
14-
SEARCH_DIR("");
13+
OUTPUT_FORMAT("elf32-littlemips", "elf32-bigmips",
14+
"elf32-littlemips")
15+
OUTPUT_ARCH(mips)
1516
ENTRY(_start)
16-
PHDRS
17-
{
18-
irxhdr 0x70000080 FLAGS (PF_R); /* 0x70000080 -> PT_SCE_IOPMOD */
19-
defhdr PT_LOAD FLAGS (PF_X | PF_W | PF_R);
20-
}
17+
SEARCH_DIR("");
18+
/* FORCE_COMMON_ALLOCATION */
19+
/* Do we need any of these for elf?
20+
__DYNAMIC = 0; */
2121
SECTIONS
2222
{
23-
. = SIZEOF_HEADERS;
24-
25-
.text 0 : ALIGN(16) {
26-
CREATE_OBJECT_SYMBOLS
27-
PROVIDE (_ftext = .) ;
28-
KEEP (* ( .module.imports )) ;
29-
* ( .text )
30-
* ( .text.* )
31-
* ( .init )
32-
* ( .fini )
33-
KEEP (* ( .module.exports )) ;
34-
PROVIDE (_etext = .) ;
35-
} :defhdr = 0
36-
37-
.rodata : ALIGN(16) {
38-
* ( .rdata )
39-
* ( .rodata )
40-
* ( .rodata1 )
41-
* ( .rodata.* )
42-
} :defhdr = 0
43-
44-
.data : ALIGN(16) {
45-
* ( .data )
46-
* ( .data1 )
47-
* ( .data.* )
48-
CONSTRUCTORS
49-
} :defhdr = 0
50-
51-
.bss : ALIGN(16) {
52-
* ( .bss )
53-
* ( .bss.* )
54-
* ( COMMON )
55-
. = ALIGN(4) ;
56-
} :defhdr
57-
_gp = ALIGN(16) ;
58-
59-
/*
60-
* This is the .iopmod section for the IRX, it contains information that
61-
* the IOP uses when loading the IRX.
62-
* This section is placed in its own segment.
63-
*/
64-
.iopmod 0 (COPY) : ALIGN(4) {
65-
/*
66-
* The linker will replace this first LONG with a pointer to _irx_id
67-
* if the symbol has been defined.
68-
*/
69-
LONG (DEFINED(_irx_id) ? ABSOLUTE(_irx_id) : 0xffffffff) ;
70-
LONG (ABSOLUTE(_start)) ;
71-
LONG (_gp) ;
72-
LONG (SIZEOF(.text)) ;
73-
LONG (SIZEOF(.data)) ;
74-
LONG (SIZEOF(.bss)) ;
75-
/*
76-
* The linker will put a SHORT here with the version of the IRX
77-
* (or zero if there is no version).
78-
*/
79-
/*
80-
* The linker will put a null terminated string here containing the
81-
* name of the IRX (or an empty string if the name is not known).
82-
*/
83-
KEEP (* ( .iopmod.version )) ;
84-
KEEP (* ( .iopmod.name )) ;
85-
FILL(0x00000000);
86-
} :irxhdr = 0
87-
88-
/*
89-
* These are the stuff that we don't want to be put in an IRX.
90-
*/
91-
/DISCARD/ : {
92-
* ( .MIPS.abiflags )
93-
* ( .comment )
94-
* ( .debug_* )
95-
* ( .gnu.attributes )
96-
* ( .mdebug.* )
97-
* ( .reginfo )
98-
* ( .symtab )
99-
* ( .strtab )
100-
* ( .shstrtab )
101-
* ( .eh_frame )
102-
/*
103-
* This must go because it confuses the IOP kernel (treated as a reloc section).
104-
*/
105-
* ( .pdr )
106-
/*
107-
* Until I can figure out if there's a better way to rid ourselves of
108-
* .rel.dyn this will have to do. - MRB
109-
*/
110-
* ( .rel.dyn )
111-
}
23+
/* Read-only sections, merged into text segment: */
24+
. = 0x0400000; /* Can conditionally be changed to . = 0x5ffe0000 + SIZEOF_HEADERS; */
25+
.interp : { *(.interp) } /* Can conditionally be removed */
26+
.reginfo : { *(.reginfo) }
27+
.hash : { *(.hash) }
28+
.dynsym : { *(.dynsym) }
29+
.dynstr : { *(.dynstr) }
30+
.gnu.version : { *(.gnu.version) }
31+
.gnu.version_d : { *(.gnu.version_d) }
32+
.gnu.version_r : { *(.gnu.version_r) }
33+
.rel.text :
34+
{ *(.rel.text) *(.rel.gnu.linkonce.t*) }
35+
.rela.text :
36+
{ *(.rela.text) *(.rela.gnu.linkonce.t*) }
37+
.rel.data :
38+
{ *(.rel.data) *(.rel.gnu.linkonce.d*) }
39+
.rela.data :
40+
{ *(.rela.data) *(.rela.gnu.linkonce.d*) }
41+
.rel.rodata :
42+
{ *(.rel.rodata) *(.rel.gnu.linkonce.r*) }
43+
.rela.rodata :
44+
{ *(.rela.rodata) *(.rela.gnu.linkonce.r*) }
45+
.rel.got : { *(.rel.got) }
46+
.rela.got : { *(.rela.got) }
47+
.rel.ctors : { *(.rel.ctors) }
48+
.rela.ctors : { *(.rela.ctors) }
49+
.rel.dtors : { *(.rel.dtors) }
50+
.rela.dtors : { *(.rela.dtors) }
51+
.rel.init : { *(.rel.init) }
52+
.rela.init : { *(.rela.init) }
53+
.rel.fini : { *(.rel.fini) }
54+
.rela.fini : { *(.rela.fini) }
55+
.rel.bss : { *(.rel.bss) }
56+
.rela.bss : { *(.rela.bss) }
57+
.rel.plt : { *(.rel.plt) }
58+
.rela.plt : { *(.rela.plt) }
59+
.init : { *(.init) } =0
60+
.plt : { *(.plt) }
61+
.text :
62+
{
63+
PROVIDE(_ftext = . );
64+
*(.text)
65+
*(.stub)
66+
/* .gnu.warning sections are handled specially by elf32.em. */
67+
*(.gnu.warning)
68+
*(.gnu.linkonce.t*)
69+
*(.mips16.fn.*) *(.mips16.call.*)
70+
} =0
71+
PROVIDE(_etext = .);
72+
PROVIDE (etext = .);
73+
.fini : { *(.fini) } =0
74+
.rodata : { *(.rodata) *(.rodata.*) *(.gnu.linkonce.r*) }
75+
.rodata1 : { *(.rodata1) }
76+
/* Adjust the address for the data segment. We want to adjust up to
77+
the same address within the page on the next page up. */
78+
. = ALIGN(0x40000) + (. & (0x40000 - 1)); /* Can conditionally be changed to . = .; */
79+
.data :
80+
{
81+
PROVIDE(_fdata = .);
82+
*(.data)
83+
*(.gnu.linkonce.d*)
84+
CONSTRUCTORS
85+
}
86+
.data1 : { *(.data1) }
87+
.ctors :
88+
{
89+
*(.ctors)
90+
}
91+
.dtors :
92+
{
93+
*(.dtors)
94+
}
95+
PROVIDE(_gp = ALIGN(16) + 0x7ff0);
96+
.got : { *(.got.plt) *(.got) }
97+
.dynamic : { *(.dynamic) }
98+
/* We want the small data sections together, so single-instruction offsets
99+
can access them all, and initialized data all before uninitialized, so
100+
we can shorten the on-disk segment size. */
101+
.sdata : { *(.sdata) }
102+
.lit8 : { *(.lit8) }
103+
.lit4 : { *(.lit4) }
104+
PROVIDE(_edata = .);
105+
PROVIDE (edata = .);
106+
__bss_start = .;
107+
PROVIDE(_fbss = .);
108+
.sbss : { *(.sbss) *(.scommon) }
109+
.bss :
110+
{
111+
*(.dynbss)
112+
*(.bss)
113+
*(COMMON)
114+
}
115+
. = ALIGN(32 / 8);
116+
PROVIDE(_end = .);
117+
PROVIDE (end = .);
118+
/* Stabs debugging sections. */
119+
.stab 0 : { *(.stab) }
120+
.stabstr 0 : { *(.stabstr) }
121+
.stab.excl 0 : { *(.stab.excl) }
122+
.stab.exclstr 0 : { *(.stab.exclstr) }
123+
.stab.index 0 : { *(.stab.index) }
124+
.stab.indexstr 0 : { *(.stab.indexstr) }
125+
.comment 0 : { *(.comment) }
126+
/* DWARF debug sections.
127+
Symbols in the DWARF debugging sections are relative to the beginning
128+
of the section so we begin them at 0. */
129+
/* DWARF 1 */
130+
.debug 0 : { *(.debug) }
131+
.line 0 : { *(.line) }
132+
/* GNU DWARF 1 extensions */
133+
.debug_srcinfo 0 : { *(.debug_srcinfo) }
134+
.debug_sfnames 0 : { *(.debug_sfnames) }
135+
/* DWARF 1.1 and DWARF 2 */
136+
.debug_aranges 0 : { *(.debug_aranges) }
137+
.debug_pubnames 0 : { *(.debug_pubnames) }
138+
/* DWARF 2 */
139+
.debug_info 0 : { *(.debug_info) }
140+
.debug_abbrev 0 : { *(.debug_abbrev) }
141+
.debug_line 0 : { *(.debug_line) }
142+
.debug_frame 0 : { *(.debug_frame) }
143+
.debug_str 0 : { *(.debug_str) }
144+
.debug_loc 0 : { *(.debug_loc) }
145+
.debug_macinfo 0 : { *(.debug_macinfo) }
146+
/* SGI/MIPS DWARF 2 extensions */
147+
.debug_weaknames 0 : { *(.debug_weaknames) }
148+
.debug_funcnames 0 : { *(.debug_funcnames) }
149+
.debug_typenames 0 : { *(.debug_typenames) }
150+
.debug_varnames 0 : { *(.debug_varnames) }
151+
/* These must appear regardless of . */
152+
.gptab.sdata : { *(.gptab.data) *(.gptab.sdata) }
153+
.gptab.sbss : { *(.gptab.bss) *(.gptab.sbss) }
154+
/*
155+
* These are the stuff that we don't want to be put in an IRX.
156+
*/
157+
/DISCARD/ : {
158+
* ( .MIPS.abiflags )
159+
}
112160
}

samples/Makefile.iopglobal_sample

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ IOP_DBGINFOFLAGS ?= -gdwarf-2 -gz
3838
# for finer-grained control over what goes into each IRX.
3939
IOP_CFLAGS := -D_IOP -fno-builtin -G0 $(IOP_OPTFLAGS) $(IOP_WARNFLAGS) $(IOP_DBGINFOFLAGS) $(IOP_INCS) $(IOP_CFLAGS)
4040
# linker flags
41-
IOP_LDFLAGS := -nostdlib -s $(IOP_LDFLAGS)
41+
IOP_LDFLAGS := -nostdlib -dc -r $(IOP_LDFLAGS)
4242

4343
# Additional C compiler flags for GCC >=v5.3.0
4444
# -msoft-float is to "remind" GCC/Binutils that the soft-float ABI is to be used. This is due to a bug, which
@@ -67,8 +67,17 @@ endif
6767
# Assembler flags
6868
IOP_ASFLAGS := $(ASFLAGS_TARGET) -EL -G0 $(IOP_ASFLAGS)
6969

70+
# Default link file
71+
ifeq ($(IOP_LINKFILE),)
72+
IOP_LINKFILE := $(PS2SDK)/iop/startup/linkfile
73+
endif
74+
7075
IOP_OBJS := $(IOP_OBJS:%=$(IOP_OBJS_DIR)%)
7176

77+
IOP_BIN_ELF := $(IOP_BIN:.irx=.notiopmod.elf)
78+
79+
IOP_BIN_STRIPPED_ELF := $(IOP_BIN:.irx=.notiopmod.stripped.elf)
80+
7281
# Externally defined variables: IOP_BIN, IOP_OBJS, IOP_LIB
7382

7483
# These macros can be used to simplify certain build rules.
@@ -110,9 +119,17 @@ $(IOP_OBJS_DIR)exports.o: $(IOP_OBJS_DIR)build-exports.c
110119
$(DIR_GUARD)
111120
$(IOP_C_COMPILE) $(IOP_IETABLE_CFLAGS) -c $< -o $@
112121

113-
$(IOP_BIN): $(IOP_OBJS)
122+
$(IOP_BIN_ELF): $(IOP_OBJS)
123+
$(DIR_GUARD)
124+
$(IOP_C_COMPILE) -T$(IOP_LINKFILE) $(IOP_OPTFLAGS) -o $@ $(IOP_OBJS) $(IOP_LDFLAGS) $(IOP_LIBS)
125+
126+
$(IOP_BIN_STRIPPED_ELF): $(IOP_BIN_ELF)
127+
$(DIR_GUARD)
128+
$(IOP_STRIP) --strip-unneeded --remove-section=.pdr --remove-section=.comment --remove-section=.mdebug.abi32 --remove-section=.gnu.attributes -o $@ $<
129+
130+
$(IOP_BIN): $(IOP_BIN_STRIPPED_ELF)
114131
$(DIR_GUARD)
115-
$(IOP_C_COMPILE) $(IOP_OPTFLAGS) -o $(IOP_BIN) $(IOP_OBJS) $(IOP_LDFLAGS) $(IOP_LIBS)
132+
iopfixup --irx1 -o $@ $<
116133

117134
$(IOP_LIB): $(IOP_OBJS)
118135
$(DIR_GUARD)

samples/Makefile.pref_sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ EE_RANLIB ?= $(EE_TOOL_PREFIX)ranlib
2929
# Defintions for the IOP toolchain.
3030
#
3131

32-
IOP_TOOL_PREFIX ?= mipsel-ps2-irx-
32+
IOP_TOOL_PREFIX ?= mipsel-none-elf-
3333
IOP_CC ?= $(IOP_TOOL_PREFIX)gcc
3434
IOP_AS ?= $(IOP_TOOL_PREFIX)as
3535
IOP_LD ?= $(IOP_TOOL_PREFIX)ld

samples/ps2dev_iop.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ endif()
2525
SET(CMAKE_SYSTEM_NAME Generic)
2626
SET(CMAKE_SYSTEM_VERSION 1)
2727
SET(CMAKE_SYSTEM_PROCESSOR mips)
28-
SET(CMAKE_C_COMPILER mipsel-ps2-irx-gcc)
29-
SET(CMAKE_CXX_COMPILER mipsel-ps2-irx-g++)
28+
SET(CMAKE_C_COMPILER mipsel-none-elf-gcc)
29+
SET(CMAKE_CXX_COMPILER mipsel-none-elf-g++)
3030
SET(CMAKE_C_COMPILER_WORKS 1) #Hack by f0bes
3131
SET(CMAKE_CXX_COMPILER_WORKS 1) #Hack by f0bes
3232

0 commit comments

Comments
 (0)