This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Add MIPS -mno-shared support


This patch adds -mno-shared support to gcc, to match the gas support that
Ian Lance Taylor added a while back.  (This has been on my to-do list for
a very long time.)

gas's -mno-shared option changes the o32, o64 and n32 gp load sequences to:

        lui     gp,%hi(__gnu_local_gp)
        addiu   gp,gp,%lo(__gnu_local_gp)

which is one instruction shorter than the norm.  This gcc patch does
the same thing.  It also uses %hi and %lo instead of GOT accesses for
locally-binding symbols and allows direct calls to locally-defined
functions.  Notes:

  - Direct calls to locally-defined symbols are safe because the callee
    will initialise gp using the sequence above.  The callee will therefore
    not need $25 to be live on entry.

  - We need to wrap direct js and jals in .option pic0/.option pic2
    in order to defeat the usual -KPIC macro expansion.

  - We can't assume that functions in other objects were compiled
    with -mno-shared, so the criterion for direct calls is
    "locally-defined" rather than "locally-binding".

Note that the optimisations do not apply to ABI_HAS_64BIT_SYMBOLS
(i.e. -mabi=64 without -msym32), where absolute sequences are much
longer than GOT accesses.

I ran CSiBE for all three mips64-linux-gnu ABIs to compare "-Os" with
"-Os -mno-shared".  The results are attached.  As you can see, the o32
and n32 output was significantly shorter after the patch.  n64 showed no
change for the reason described above.

I also bootstrapped & regression-tested the patch on mips64-linux-gnu with
the following hunk:

Index: gcc/config/mips/linux64.h
===================================================================
--- gcc/config/mips/linux64.h	(revision 112199)
+++ gcc/config/mips/linux64.h	(working copy)
@@ -22,6 +22,7 @@ the Free Software Foundation; either ver
 /* Force the default endianness and ABI flags onto the command line
    in order to make the other specs easier to write.  */
 #define DRIVER_SELF_SPECS \
+"%{!mshared:%{!mno-shared:%{fpic|fPIC|fpie|fPIE:-mshared;:-mno-shared}}}", \
 "%{!EB:%{!EL:%(endian_spec)}}", \
 "%{!mabi=*: -mabi=n32}"
 
also applied.  I don't plan to commit this part; it was just something
I used for testing.  However, I would like to make -mno-shared the default
for GNU/Linux if gcc is configured to use a version of binutils that
supports it.  In other words, I'd like to have something like the above,
but conditional on a configure-time option whose default is derived from
the binutils version.

(The current default doesn't make much sense to me.  The code it
generates can't really be used in shared libraries, because without
-fpic or -fPIC, gcc will use executable rather than DSO binding rules.
For example, -finline-functions will inline global functions by default,
but not when -fPIC or -fpic is used.)

I'd appreciate comments from people who regularly build GNU/Linux
systems though.  Is this a mad idea?

In the meantime, applied to trunk as seen below.

Richard


	* config/mips/predicates.md (const_call_insn_operand): Allow direct
	calls to locally-defined functions if TARGET_ABSOLUTE_ABICALLS.
	* config/mips/mips.md (jal_macro): Test TARGET_ABSOLUTE_ABICALLS.
	Use TARGET_OLDABI instead of !TARGET_NEWABI.
	(loadgp): Use mips_current_loadgp_style.
	(loadgp_noshared): New pattern.
	(sibcall_internal): Use MIPS_CALL.
	(sibcall_value_internal): Likewise.
	(sibcall_value_multiple_internal): Likewise.
	(call_internal): Likewise.
	(call_value_internal): Likewise.
	(call_value_multiple_internal): Likewise.
	(call_split): Use MIPS_CALL and add an 'S' constraint.
	(call_value_split): Likewise.
	(call_value_multiple_split): Likewise.
	* config/mips/mips.opt (-mabicalls): Tweak docstring.
	(-mshared): New option.
	* config/mips/mips-protos.h (mips_loadgp_style): New enum.
	(mips_current_loadgp_style): Declare.
	* config/mips/mips.c (mips_classify_symbol): Avoid using
	SYMBOL_GOT_LOCAL if TARGET_ABSOLUTE_ABICALLS.  Use SYMBOL_GENERAL
	rather than SYMBOL_GOT_GLOBAL for locally-binding symbols if
	TARGET_ABSOLUTE_ABICALLS.
	(override_options): Adjust comments.  Improve the warning that is
	issued when -mabicalls and -G are used together.
	(mips_file_start): Remove comment.
	(mips_current_loadgp_style): New function.
	(mips_gnu_local_gp): New variable.
	(mips_emit_loadgp): Use mips_current_loadgp_style.  Handle
	LOADGP_ABSOLUTE.
	(mips_output_function_prologue): Use mips_current_laodgp_style.
	(mips_expand_prologue): Call mips_emit_loadgp before emitting
	the cprestore instruction.
	(mips_extra_live_on_entry): Fix reversed test.  Don't make $25
	live for TARGET_ABSOLUTE_ABICALLS.
	* config/mips/mips.h (TARGET_ABSOLUTE_ABICALLS): New macro.
	(ASM_SPEC): Pass down -mshared and -mno-shared.
	(MIPS_CALL): New macro.
	* config/mips/netbsd.h (TARGET_OS_CPP_BUILTINS): Remove __ABICALLS__
	definition.
	* doc/invoke.texi (-mabicalls): Update documentation.
	(-mshared): Document.

Attachment: mshared.diff
Description: Text document

Attachment: csibe-32.txt
Description: Text document

Attachment: csibe-n32.txt
Description: Text document

Attachment: csibe-64.txt
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]