diff mbox

[v3,2/2] ext-toolchain-wrapper: fix uboot/linux with hardfp

Message ID 1374276718-14000-2-git-send-email-spenser@gillilanding.com
State Accepted
Headers show

Commit Message

Spenser Gilliland July 19, 2013, 11:31 p.m. UTC
The linux kernel and uboot specify -msoft-float in order to prevent floating
point code from being generated.  This causes a conflict when -mfloat-abi=hard
or -mfloat-abi options are specified in the wrapper. This patch removes the
-mfloat-abi option from the options generated by the wrapper only when -msoft-float, -mhard-float or -mfloat-abi are specified by the user.

Signed-off-by: Spenser Gilliland <spenser@gillilanding.com>
---
 .../toolchain-external/ext-toolchain-wrapper.c     | 37 +++++++++++++++++++---
 1 file changed, 33 insertions(+), 4 deletions(-)

Comments

Yann E. MORIN July 20, 2013, 10:36 a.m. UTC | #1
Spenser, All,

On 2013-07-19 18:31 -0500, Spenser Gilliland spake thusly:
> The linux kernel and uboot specify -msoft-float in order to prevent floating
> point code from being generated.  This causes a conflict when -mfloat-abi=hard
> or -mfloat-abi options are specified in the wrapper. This patch removes the
> -mfloat-abi option from the options generated by the wrapper only when -msoft-float, -mhard-float or -mfloat-abi are specified by the user.

Please, wrap your commit log at <80 chars.

> 
> Signed-off-by: Spenser Gilliland <spenser@gillilanding.com>

Tested-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Reviewed-by: "Yann E. MORIN" <yann.morin.1998@free.fr>

Yet a few minor nits below.

Regards,
Yann E. MORIN.

> ---
>  .../toolchain-external/ext-toolchain-wrapper.c     | 37 +++++++++++++++++++---
>  1 file changed, 33 insertions(+), 4 deletions(-)
> 
> diff --git a/toolchain/toolchain-external/ext-toolchain-wrapper.c b/toolchain/toolchain-external/ext-toolchain-wrapper.c
> index dc473be..3b70610 100644
> --- a/toolchain/toolchain-external/ext-toolchain-wrapper.c
> +++ b/toolchain/toolchain-external/ext-toolchain-wrapper.c
[--SNIP--]
> @@ -61,6 +59,25 @@ static char *predef_args[] = {
>  #endif
>  };
>  
> +/* use_default_float_abi - determine if the user is trying to override the
> + * floating point abi.
> + *  return 0 if the user is attempting to override the float abi
> + *  otherwise return 1

I'd state it differently:

  use_default_float_abi - check whether we should pass our own float ABI
  flags, or use the ones provided on the command line
  Returns:
    0: do not add our -float-abi= flag
    1: do add our -mfloat-abi= flags

> + */
> +int use_default_float_abi(int argc, char **argv) {
> +	int arg;
> +	for (arg = 1; arg < argc; arg++) {
> +		if (strncmp(argv[arg],"-mfloat-abi=", sizeof("-mfloat-abi=")/sizeof(char)-1) == 0 ||

I think that we can assume that sizeof(char) == 1 everywhere Buildroot
is expected to run, no? ;-)

> +			strcmp(argv[arg],"-msoft-float") == 0 ||
> +			strcmp(argv[arg],"-mhard-float") == 0 ) {
> +			printf("DETECTED FLOAT ABI\n");
> +			return 0;
> +		}
> +	}
> +	

No spaces/tabs on empty lines.

Otherwise, loogs good, and most importantly, fixes my kernel build!
Hurray! :-)

Regards,
Yann E. MORIN.
Peter Korsgaard July 20, 2013, 10:59 p.m. UTC | #2
>>>>> "Spenser" == Spenser Gilliland <spenser@gillilanding.com> writes:

 Spenser> The linux kernel and uboot specify -msoft-float in order to
 Spenser> prevent floating point code from being generated.  This causes
 Spenser> a conflict when -mfloat-abi=hard or -mfloat-abi options are
 Spenser> specified in the wrapper. This patch removes the -mfloat-abi
 Spenser> option from the options generated by the wrapper only when
 Spenser> -msoft-float, -mhard-float or -mfloat-abi are specified by the
 Spenser> user.

Committed with some changes (see below) - Thanks.

 Spenser> +/* use_default_float_abi - determine if the user is trying to override the
 Spenser> + * floating point abi.
 Spenser> + *  return 0 if the user is attempting to override the float abi
 Spenser> + *  otherwise return 1
 Spenser> + */
 Spenser> +int use_default_float_abi(int argc, char **argv) {
 Spenser> +	int arg;
 Spenser> +	for (arg = 1; arg < argc; arg++) {
 Spenser> +		if (strncmp(argv[arg],"-mfloat-abi=", sizeof("-mfloat-abi=")/sizeof(char)-1) == 0 ||
 Spenser> +			strcmp(argv[arg],"-msoft-float") == 0 ||
 Spenser> +			strcmp(argv[arg],"-mhard-float") == 0 ) {
 Spenser> +			printf("DETECTED FLOAT ABI\n");

This debug line shouldn't be here.

The entire function should be inside an #ifdef BR_FLOAT_ABI so we don't
get warnings about unused functions on !arm.

 Spenser> +			return 0;
 Spenser> +		}
 Spenser> +	}
 Spenser> +	
 Spenser> +	return 1;
 Spenser> +}
 Spenser> +
 Spenser>  int main(int argc, char **argv)
 Spenser>  {
 Spenser>  	char **args, **cur;
 Spenser> @@ -68,6 +85,11 @@ int main(int argc, char **argv)
 Spenser>  	char *progpath = argv[0];
 Spenser>  	char *basename;
 Spenser>  	int ret, i, count = 0;
 Spenser> +	int set_float_abi = 0;
 Spenser> +
 Spenser> +#ifdef BR_FLOAT_ABI
 Spenser> +	set_float_abi = use_default_float_abi(argc,argv);
 Spenser> +#endif
 
 Spenser>  	/* Calculate the relative paths */
 Spenser>  	basename = strrchr(progpath, '/');
 Spenser> @@ -119,7 +141,8 @@ int main(int argc, char **argv)
 Spenser>  		return 3;
 Spenser>  	}
 
 Spenser> -	cur = args = malloc(sizeof(predef_args) + (sizeof(char *) * argc));
 Spenser> +	cur = args = malloc(sizeof(predef_args) +
 Spenser> +		(sizeof(char *) * (argc + set_float_abi)));
 Spenser>  	if (args == NULL) {
 Spenser>  		perror(__FILE__ ": malloc");
 Spenser>  		return 2;
 Spenser> @@ -129,6 +152,12 @@ int main(int argc, char **argv)
 Spenser>  	memcpy(cur, predef_args, sizeof(predef_args));
 Spenser>  	cur += sizeof(predef_args) / sizeof(predef_args[0]);
 
 Spenser> +	/* add float abi if neccessary */

It's more 'if not overridden by the wrapper arguments'

 Spenser> +	if (set_float_abi) {
 Spenser> +		*cur = "-mfloat-abi=" BR_FLOAT_ABI;
 Spenser> +		cur++;
 Spenser> +	}

This should also have been inside an #ifdef BR_FLOAT_ABI, because now it
won't build on archs not using BR_FLOAT_ABI.

To limit the number of ifdefs, I simply moved the
use_default_float_abi() function inline here.
diff mbox

Patch

diff --git a/toolchain/toolchain-external/ext-toolchain-wrapper.c b/toolchain/toolchain-external/ext-toolchain-wrapper.c
index dc473be..3b70610 100644
--- a/toolchain/toolchain-external/ext-toolchain-wrapper.c
+++ b/toolchain/toolchain-external/ext-toolchain-wrapper.c
@@ -8,6 +8,7 @@ 
  * (C) 2011 Peter Korsgaard <jacmet@sunsite.dk>
  * (C) 2011 Daniel Nyström <daniel.nystrom@timeterminal.se>
  * (C) 2012 Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
+ * (C) 2013 Spenser Gilliland <spenser@gillilanding.com>
  *
  * This file is licensed under the terms of the GNU General Public License
  * version 2.  This program is licensed "as is" without any warranty of any
@@ -38,9 +39,6 @@  static char *predef_args[] = {
 #ifdef BR_ABI
 	"-mabi=" BR_ABI,
 #endif
-#ifdef BR_FLOAT_ABI
-	"-mfloat-abi=" BR_FLOAT_ABI,
-#endif
 #ifdef BR_FPU
 	"-mfpu=" BR_FPU,
 #endif
@@ -61,6 +59,25 @@  static char *predef_args[] = {
 #endif
 };
 
+/* use_default_float_abi - determine if the user is trying to override the
+ * floating point abi.
+ *  return 0 if the user is attempting to override the float abi
+ *  otherwise return 1
+ */
+int use_default_float_abi(int argc, char **argv) {
+	int arg;
+	for (arg = 1; arg < argc; arg++) {
+		if (strncmp(argv[arg],"-mfloat-abi=", sizeof("-mfloat-abi=")/sizeof(char)-1) == 0 ||
+			strcmp(argv[arg],"-msoft-float") == 0 ||
+			strcmp(argv[arg],"-mhard-float") == 0 ) {
+			printf("DETECTED FLOAT ABI\n");
+			return 0;
+		}
+	}
+	
+	return 1;
+}
+
 int main(int argc, char **argv)
 {
 	char **args, **cur;
@@ -68,6 +85,11 @@  int main(int argc, char **argv)
 	char *progpath = argv[0];
 	char *basename;
 	int ret, i, count = 0;
+	int set_float_abi = 0;
+
+#ifdef BR_FLOAT_ABI
+	set_float_abi = use_default_float_abi(argc,argv);
+#endif
 
 	/* Calculate the relative paths */
 	basename = strrchr(progpath, '/');
@@ -119,7 +141,8 @@  int main(int argc, char **argv)
 		return 3;
 	}
 
-	cur = args = malloc(sizeof(predef_args) + (sizeof(char *) * argc));
+	cur = args = malloc(sizeof(predef_args) +
+		(sizeof(char *) * (argc + set_float_abi)));
 	if (args == NULL) {
 		perror(__FILE__ ": malloc");
 		return 2;
@@ -129,6 +152,12 @@  int main(int argc, char **argv)
 	memcpy(cur, predef_args, sizeof(predef_args));
 	cur += sizeof(predef_args) / sizeof(predef_args[0]);
 
+	/* add float abi if neccessary */
+	if (set_float_abi) {
+		*cur = "-mfloat-abi=" BR_FLOAT_ABI;
+		cur++;
+	}
+
 	/* append forward args */
 	memcpy(cur, &argv[1], sizeof(char *) * (argc - 1));
 	cur += argc - 1;