On {mips,mipsel,mips64,mips64el}-freebsd, we need to pass any -G option to the linker. See also:
https://gcc.gnu.org/onlinedocs/gcc/MIPS-Options.html#index-G-2007
This has been adapted from https://reviews.freebsd.org/D1190, with an added test case.
Differential D9114
For FreeBSD on mips, pass -G options to the linker Authored by dim on Apr 20 2015, 10:59 AM.
Details On {mips,mipsel,mips64,mips64el}-freebsd, we need to pass any -G option to the linker. See also: https://gcc.gnu.org/onlinedocs/gcc/MIPS-Options.html#index-G-2007 This has been adapted from https://reviews.freebsd.org/D1190, with an added test case.
Diff Detail Event TimelineComment Actions Added Simon as a reviewer, as he is more knowledgeable than me about the frontend and linkers. Comment Actions Is it necessary on FreeBSD to pass the -G option to the assembler as well as to the linker? Comment Actions Hm, yes, you are right about that. With our copy of gcc for mips, I see that it passes that flag: /usr/obj/mips.mips/usr/src/tmp/usr/bin/as -G0 -EB -no-mdebug -mabi=32 -march=mips3 -v -KPIC -o foo.o foo.s in addition to passing it to the linker: /usr/obj/mips.mips/usr/src/tmp/usr/bin/ld --eh-frame-hdr -EB -EB -G0 -melf32btsmip_fbsd -V --enable-new-dtags -dynamic-linker /libexec/ld-elf.so.1 -o foo crt1.o crti.o crtbegin.o -L/usr/obj/mips.mips/usr/src/tmp/usr/lib -L/usr/obj/mips.mips/usr/src/tmp/usr/lib foo.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed crtend.o crtn.o @seanbruno, @emaste, any idea about this? I think the patch as-is now incomplete, as we must also make sure any -G flag is passed to the assembler too, or is applied to the integrated assembler, though I have no clue how to do that. :-) And of course we should extend the test cases for it. Comment Actions Even if this patch is incomplete with regards to the assembler, it is both necessary and sufficient to build and link programs with the current FreeBSD build system. It follows gcc's long established behavior as a linker and is harmless to other consumers so why not commit it? All that being said, I'm not actually sure -G does anything at all when pasted to ld and as. The binutils documentation says it's only for ECOFF targets so in practice it may be a no-op. Comment Actions Sure, but maybe -G for the linker is not completely useful, if the assembler also doesn't use it?
The GNU as documentation here: https://sourceware.org/binutils/docs/as/MIPS-Options.html#index-g_t_0040code_007b_002dG_007d-option-_0028MIPS_0029-1392 says:
but it doesn't talk about ECOFF, and neither does the referenced section about "small data": https://sourceware.org/binutils/docs/as/MIPS-Small-Data.html The GNU ld documentation here: https://sourceware.org/binutils/docs/ld/Options.html#index-g_t_002dG-_0040var_007bvalue_007d-47 says:
So it doesn't talk about ECOFF either, but explicitly mentions ELF... Comment Actions Likely true, though we've managed to run quite a bit of code built without it. See http://reviews.llvm.org/D10137 for a fix to the non-integrated-as case.
FreeBSD 10's as manpage says: -G num
This option sets the largest size of an object that can be referenced implicitly with the "gp" register. It is only accepted for targets that use ECOFF format, such as a DECstation running Ultrix. The default value is 8.
FreeBSD 10's ld says: -Gvalue --gpsize=value Set the maximum size of objects to be optimized using the GP register to size. This is only meaningful for object file formats such as MIPS ECOFF which supports putting large and small objects into different sections. This is ignored for other object file formats. |