From d3719ee2c078a1518c9e21efae0cf438d4ffb8d6 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Wed, 24 Jan 2018 23:36:29 +0000 Subject: [PATCH] Fix m68k-linux-gnu libgcc build for ColdFire (PR target/68467). PR target/68467 is libgcc failing to build for m68k-linux-gnu configured for ColdFire. Jeff has an analysis in the PR identifying the problem as resulting from the callers of libcalls with 1-byte or 2-byte arguments wanting to push just 1 or 2 bytes on the stack, while the libcall implementations have the normal C ABI and expect 4-byte arguments. For normal C functions, I believe the TARGET_PROMOTE_PROTOTYPES definition would ensure such arguments get passed as 4-byte, but that does not apply for libcalls. This patch fixes the issue by defining TARGET_PROMOTE_FUNCTION_MODE for m68k. The definition is conservative, only applying promotions in the case of arguments to libcalls; otherwise it returns the unpromoted type, which I believe matches what the default implementation of the hook would have done on m68k. I have tested that this fixes the libgcc build for ColdFire, and, in conjunction with one glibc patch, this enables glibc to build cleanly for ColdFire and to pass the compilation parts of the glibc testsuite except for one test unrelated to this patch (while glibc and the compilation parts of the testsuite continue to build OK for non-ColdFire m68k, as expected). I have *not* run any GCC tests for this patch, or any execution tests for m68k. PR target/68467 * config/m68k/m68k.c (m68k_promote_function_mode): New function. (TARGET_PROMOTE_FUNCTION_MODE): New macro. From-SVN: r257032 --- gcc/ChangeLog | 6 ++++++ gcc/config/m68k/m68k.c | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 9427ef89b53..c46bc6d6f9d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2018-01-24 Joseph Myers + + PR target/68467 + * config/m68k/m68k.c (m68k_promote_function_mode): New function. + (TARGET_PROMOTE_FUNCTION_MODE): New macro. + 2017-01-08 Jeff Law PR target/83994 diff --git a/gcc/config/m68k/m68k.c b/gcc/config/m68k/m68k.c index 9e35357c897..495a80b759e 100644 --- a/gcc/config/m68k/m68k.c +++ b/gcc/config/m68k/m68k.c @@ -192,6 +192,8 @@ m68k_excess_precision (enum excess_precision_type); static unsigned int m68k_hard_regno_nregs (unsigned int, machine_mode); static bool m68k_hard_regno_mode_ok (unsigned int, machine_mode); static bool m68k_modes_tieable_p (machine_mode, machine_mode); +static machine_mode m68k_promote_function_mode (const_tree, machine_mode, + int *, const_tree, int); /* Initialize the GCC target structure. */ @@ -347,6 +349,9 @@ static bool m68k_modes_tieable_p (machine_mode, machine_mode); #undef TARGET_MODES_TIEABLE_P #define TARGET_MODES_TIEABLE_P m68k_modes_tieable_p +#undef TARGET_PROMOTE_FUNCTION_MODE +#define TARGET_PROMOTE_FUNCTION_MODE m68k_promote_function_mode + static const struct attribute_spec m68k_attribute_table[] = { /* { name, min_len, max_len, decl_req, type_req, fn_type_req, @@ -6621,4 +6626,20 @@ m68k_push_rounding (poly_int64 bytes) return (bytes + 1) & ~1; } +/* Implement TARGET_PROMOTE_FUNCTION_MODE. */ + +static machine_mode +m68k_promote_function_mode (const_tree type, machine_mode mode, + int *punsignedp ATTRIBUTE_UNUSED, + const_tree fntype ATTRIBUTE_UNUSED, + int for_return) +{ + /* Promote libcall arguments narrower than int to match the normal C + ABI (for which promotions are handled via + TARGET_PROMOTE_PROTOTYPES). */ + if (type == NULL_TREE && !for_return && (mode == QImode || mode == HImode)) + return SImode; + return mode; +} + #include "gt-m68k.h" -- 2.30.2