This is an archive of the discontinued LLVM Phabricator instance.

For FreeBSD on mips, pass -G options to the linker
ClosedPublic

Authored by dim on Apr 20 2015, 10:59 AM.

Diff Detail

Event Timeline

dim updated this revision to Diff 24031.Apr 20 2015, 10:59 AM
dim retitled this revision from to For FreeBSD on mips, pass -G options to the linker.
dim updated this object.
dim edited the test plan for this revision. (Show Details)
dim added reviewers: emaste, theraven.
dim added a subscriber: seanbruno.
dim added a subscriber: Unknown Object (MLST).Apr 20 2015, 11:00 AM

Added Simon as a reviewer, as he is more knowledgeable than me about the frontend and linkers.

atanasyan edited edge metadata.May 22 2015, 1:21 AM

Is it necessary on FreeBSD to pass the -G option to the assembler as well as to the linker?

dim added a comment.May 29 2015, 11:30 AM

Is it necessary on FreeBSD to pass the -G option to the assembler as well as to the linker?

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.

brooks added a subscriber: brooks.May 29 2015, 12:27 PM

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.

dim added a comment.May 29 2015, 12:38 PM

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?

Sure, but maybe -G for the linker is not completely useful, if the assembler also doesn't use 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.

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:

Set the “small data” limit to n bytes. The default limit is 8 bytes. See Controlling the use of small data accesses.

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:

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 ELF that support putting large and small objects into different sections. This is ignored for other object file formats.

So it doesn't talk about ECOFF either, but explicitly mentions ELF...

In D9114#181178, @dim wrote:

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?

Sure, but maybe -G for the linker is not completely useful, if the assembler also doesn't use it?

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.

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.

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:

Set the “small data” limit to n bytes. The default limit is 8 bytes. See Controlling the use of small data accesses.

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

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.

The GNU ld documentation here: https://sourceware.org/binutils/docs/ld/Options.html#index-g_t_002dG-_0040var_007bvalue_007d-47 says:

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 ELF that support putting large and small objects into different sections. This is ignored for other object file formats.

So it doesn't talk about ECOFF either, but explicitly mentions ELF...

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.
emaste accepted this revision.Dec 26 2015, 11:26 AM
emaste edited edge metadata.
This revision is now accepted and ready to land.Dec 26 2015, 11:26 AM
dim closed this revision.Dec 26 2015, 10:50 PM