public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] add uClibc target hook (PR bootstrap/77819)
@ 2016-10-02 22:02 Martin Sebor
  2016-10-04  8:42 ` Bernd Schmidt
  0 siblings, 1 reply; 6+ messages in thread
From: Martin Sebor @ 2016-10-02 22:02 UTC (permalink / raw)
  To: Gcc Patch List

[-- Attachment #1: Type: text/plain, Size: 361 bytes --]

The attached patch adds a uclibc_printf_pointer_format target
hook equivalent to the linux glibc_printf_pointer_format hook.
I couldn't find a good uclibc-only file where to put the new
definition of the hook so I conditionally added it to
targethooks.c.

I tested the new hook by bootstrapping GCC for tic6x-uclinux
and bfin-uclinux targets on x86_64.

Martin

[-- Attachment #2: gcc-77819.diff --]
[-- Type: text/x-patch, Size: 3007 bytes --]

PR bootstrap/77819 - undefined reference to gnu_libc_printf_pointer_format with uClibc

gcc/ChangeLog:
2016-10-02  Martin Sebor  <msebor@redhat.com>

	PR bootstrap/77819
	* config/linux.h [DEFAULT_LIBC == LIBC_UCLIBC) && SINGLE_LIBC]
	(TARGET_PRINTF_POINTER_FORMAT): Define macro.
	* targhooks.c [DEFAULT_LIBC == LIBC_UCLIBC) && SINGLE_LIBC]
	(default_printf_pointer_format): Define function.
	* targhooks.h (default_printf_pointer_format): Declare.

diff --git a/gcc/config/linux.h b/gcc/config/linux.h
index 3ff005b..1649b01 100644
--- a/gcc/config/linux.h
+++ b/gcc/config/linux.h
@@ -200,6 +200,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 # undef TARGET_LIBC_HAS_FUNCTION
 # define TARGET_LIBC_HAS_FUNCTION no_c99_libc_has_function
 
+/* The format string to which "%p" corresponds.  */
+#  undef TARGET_PRINTF_POINTER_FORMAT
+#  define TARGET_PRINTF_POINTER_FORMAT uclibc_printf_pointer_format
+
 #else /* !uClinux, i.e., normal Linux */
 
 /* Determine what functions are present at the runtime;
@@ -207,8 +211,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 # undef TARGET_LIBC_HAS_FUNCTION
 # define TARGET_LIBC_HAS_FUNCTION linux_libc_has_function
 
-#endif
-
 /* The format string to which "%p" corresponds.  */
-#undef TARGET_PRINTF_POINTER_FORMAT
-#define TARGET_PRINTF_POINTER_FORMAT gnu_libc_printf_pointer_format
+#  undef TARGET_PRINTF_POINTER_FORMAT
+#  define TARGET_PRINTF_POINTER_FORMAT gnu_libc_printf_pointer_format
+
+#endif
diff --git a/gcc/targhooks.c b/gcc/targhooks.c
index d75650f..77b4a18 100644
--- a/gcc/targhooks.c
+++ b/gcc/targhooks.c
@@ -1523,6 +1523,26 @@ default_printf_pointer_format (tree, const char **flags)
   return "%zx";
 }
 
+#if (DEFAULT_LIBC == LIBC_UCLIBC) && defined (SINGLE_LIBC) /* uClinux */
+
+/* For *uclibc* targets only, define the hook here because otherwise
+   it would have to be duplicated in each target's .c file (such as
+   in bfin/bfin.c and c6x/c6x.c, etc.)
+   uClibc (and Glibc) format pointers as if by "%zx" except for the null
+   pointer which outputs "(nil)".  It ignores the pound ('#') format
+   flag but interprets the space and plus flags the same as in the integer
+   directive.  */
+
+const char*
+uclibc_printf_pointer_format (tree arg, const char **flags)
+{
+  *flags = " +";
+
+  return arg && integer_zerop (arg) ? "(nil)" : "%#zx";
+}
+
+#endif
+
 tree
 default_builtin_tm_load_store (tree ARG_UNUSED (type))
 {
diff --git a/gcc/targhooks.h b/gcc/targhooks.h
index 3356f0a..52d36e0 100644
--- a/gcc/targhooks.h
+++ b/gcc/targhooks.h
@@ -194,6 +194,7 @@ extern bool gnu_libc_has_function (enum function_class);
 extern const char* default_printf_pointer_format (tree, const char **);
 extern const char* gnu_libc_printf_pointer_format (tree, const char **);
 extern const char* solaris_printf_pointer_format (tree, const char **);
+extern const char* uclibc_printf_pointer_format (tree, const char **);
 
 extern tree default_builtin_tm_load_store (tree);
 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] add uClibc target hook (PR bootstrap/77819)
  2016-10-02 22:02 [PATCH] add uClibc target hook (PR bootstrap/77819) Martin Sebor
@ 2016-10-04  8:42 ` Bernd Schmidt
  2016-10-04 14:34   ` Martin Sebor
  0 siblings, 1 reply; 6+ messages in thread
From: Bernd Schmidt @ 2016-10-04  8:42 UTC (permalink / raw)
  To: Martin Sebor, Gcc Patch List

On 10/03/2016 12:02 AM, Martin Sebor wrote:
> I couldn't find a good uclibc-only file where to put the new
> definition of the hook so I conditionally added it to
> targethooks.c.

> diff --git a/gcc/targhooks.c b/gcc/targhooks.c
> index d75650f..77b4a18 100644
> --- a/gcc/targhooks.c
> +++ b/gcc/targhooks.c
> @@ -1523,6 +1523,26 @@ default_printf_pointer_format (tree, const char **flags)
>    return "%zx";
>  }
>
> +#if (DEFAULT_LIBC == LIBC_UCLIBC) && defined (SINGLE_LIBC) /* uClinux */

I think DEFAULT_LIBC is defined only for linux targets, so this won't 
do. Just define unconditionally, with a declaration in targhooks.h?

> +const char*
> +uclibc_printf_pointer_format (tree arg, const char **flags)
> +{
> +  *flags = " +";
> +
> +  return arg && integer_zerop (arg) ? "(nil)" : "%#zx";
> +}

Then again, maybe also just move the hook from linux.c here, it appears 
identical.


Bernd

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] add uClibc target hook (PR bootstrap/77819)
  2016-10-04  8:42 ` Bernd Schmidt
@ 2016-10-04 14:34   ` Martin Sebor
  2016-10-04 14:54     ` Bernd Schmidt
  0 siblings, 1 reply; 6+ messages in thread
From: Martin Sebor @ 2016-10-04 14:34 UTC (permalink / raw)
  To: Bernd Schmidt, Gcc Patch List

On 10/04/2016 02:42 AM, Bernd Schmidt wrote:
> On 10/03/2016 12:02 AM, Martin Sebor wrote:
>> I couldn't find a good uclibc-only file where to put the new
>> definition of the hook so I conditionally added it to
>> targethooks.c.
>
>> diff --git a/gcc/targhooks.c b/gcc/targhooks.c
>> index d75650f..77b4a18 100644
>> --- a/gcc/targhooks.c
>> +++ b/gcc/targhooks.c
>> @@ -1523,6 +1523,26 @@ default_printf_pointer_format (tree, const char
>> **flags)
>>    return "%zx";
>>  }
>>
>> +#if (DEFAULT_LIBC == LIBC_UCLIBC) && defined (SINGLE_LIBC) /* uClinux */
>
> I think DEFAULT_LIBC is defined only for linux targets, so this won't
> do. Just define unconditionally, with a declaration in targhooks.h?

I copied the conditional from config/linux.h but I admit I don't
fully understand when the macro is defined.  Should I still remove
it from targhooks.c?

>
>> +const char*
>> +uclibc_printf_pointer_format (tree arg, const char **flags)
>> +{
>> +  *flags = " +";
>> +
>> +  return arg && integer_zerop (arg) ? "(nil)" : "%#zx";
>> +}
>
> Then again, maybe also just move the hook from linux.c here, it appears
> identical.

Yes, the glibc and uclibc hooks are the same.  I don't know what
the convention is for these target hooks (i.e., whether they are
expected to be duplicated across targets even if they are the
same to reduce the risk of breaking one target as a result of
changing another, or whether duplication should be avoided even
at this risk).  From your comment it sounds like it should be
the latter and I'm okay with that.

Thanks
Martin

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] add uClibc target hook (PR bootstrap/77819)
  2016-10-04 14:34   ` Martin Sebor
@ 2016-10-04 14:54     ` Bernd Schmidt
  2016-10-04 20:25       ` Martin Sebor
  0 siblings, 1 reply; 6+ messages in thread
From: Bernd Schmidt @ 2016-10-04 14:54 UTC (permalink / raw)
  To: Martin Sebor, Gcc Patch List

On 10/04/2016 04:34 PM, Martin Sebor wrote:
>
> I copied the conditional from config/linux.h but I admit I don't
> fully understand when the macro is defined.

AFAICT it's done in config.gcc, for a limited set of targets.

> Should I still remove it from targhooks.c?

That is compiled for all targets, not just for those which define the 
macro, so yes.

> Yes, the glibc and uclibc hooks are the same.  I don't know what
> the convention is for these target hooks (i.e., whether they are
> expected to be duplicated across targets even if they are the
> same to reduce the risk of breaking one target as a result of
> changing another, or whether duplication should be avoided even
> at this risk).  From your comment it sounds like it should be
> the latter and I'm okay with that.

There's arguments for both. In this particular case I don't see a strong 
reason not to have a general hook available.


Bernd

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] add uClibc target hook (PR bootstrap/77819)
  2016-10-04 14:54     ` Bernd Schmidt
@ 2016-10-04 20:25       ` Martin Sebor
  2016-10-05 10:38         ` Bernd Schmidt
  0 siblings, 1 reply; 6+ messages in thread
From: Martin Sebor @ 2016-10-04 20:25 UTC (permalink / raw)
  To: Bernd Schmidt, Gcc Patch List

[-- Attachment #1: Type: text/plain, Size: 1316 bytes --]

On 10/04/2016 08:54 AM, Bernd Schmidt wrote:
> On 10/04/2016 04:34 PM, Martin Sebor wrote:
>>
>> I copied the conditional from config/linux.h but I admit I don't
>> fully understand when the macro is defined.
>
> AFAICT it's done in config.gcc, for a limited set of targets.
>
>> Should I still remove it from targhooks.c?
>
> That is compiled for all targets, not just for those which define the
> macro, so yes.
>
>> Yes, the glibc and uclibc hooks are the same.  I don't know what
>> the convention is for these target hooks (i.e., whether they are
>> expected to be duplicated across targets even if they are the
>> same to reduce the risk of breaking one target as a result of
>> changing another, or whether duplication should be avoided even
>> at this risk).  From your comment it sounds like it should be
>> the latter and I'm okay with that.
>
> There's arguments for both. In this particular case I don't see a strong
> reason not to have a general hook available.

Sounds good.  Attached is an updated patch reflecting these changes.
Restested by building the powerpc64-linux and tic6x-uclinux cross
toolchains.  (Sharing the Glibc and uClibc implementation of the
target hook and defining it in targhooks.c also obviates the patch
I sent in for bug 77837 last night so it seems like a win-win.)

Martin

[-- Attachment #2: gcc-77819.diff --]
[-- Type: text/x-patch, Size: 3466 bytes --]

PR bootstrap/77819 - undefined reference to gnu_libc_printf_pointer_format with uClibc

gcc/ChangeLog:

	PR bootstrap/77819
	* config/linux.h (TARGET_PRINTF_POINTER_FORMAT): Define macro.
	* config/linux.c (gnu_libc_printf_pointer_format): Remove.
	* targhooks.c [DEFAULT_LIBC == LIBC_UCLIBC) && SINGLE_LIBC]
	(default_printf_pointer_format): Define function.
	* targhooks.c (linux_printf_pointer_format): Define new function.
	* targhooks.h (linux_printf_pointer_format): Declare.
	(gnu_libc_printf_pointer_format): Remove declaration.

diff --git a/gcc/config/linux.c b/gcc/config/linux.c
index 9aac38b..a393d3b 100644
--- a/gcc/config/linux.c
+++ b/gcc/config/linux.c
@@ -24,9 +24,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree.h"
 #include "linux-protos.h"
 
-#undef TARGET_PRINTF_POINTER_FORMAT
-#define TARGET_PRINTF_POINTER_FORMAT gnu_libc_printf_pointer_format
-
 bool
 linux_libc_has_function (enum function_class fn_class)
 {
@@ -40,16 +37,3 @@ linux_libc_has_function (enum function_class fn_class)
 
   return false;
 }
-
-/* Glibc formats pointers as if by "%zx" except for the null pointer
-   which outputs "(nil)".  It ignores the pound ('#') format flag but
-   interprets the space and plus flags the same as in the integer
-   directive.  */
-
-const char*
-gnu_libc_printf_pointer_format (tree arg, const char **flags)
-{
-  *flags = " +";
-
-  return arg && integer_zerop (arg) ? "(nil)" : "%#zx";
-}
diff --git a/gcc/config/linux.h b/gcc/config/linux.h
index 3ff005b..7211da2 100644
--- a/gcc/config/linux.h
+++ b/gcc/config/linux.h
@@ -209,6 +209,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #endif
 
-/* The format string to which "%p" corresponds.  */
+/* The format string to which "%p" corresponds (same in Glibc and
+   uClibc.  */
 #undef TARGET_PRINTF_POINTER_FORMAT
-#define TARGET_PRINTF_POINTER_FORMAT gnu_libc_printf_pointer_format
+#define TARGET_PRINTF_POINTER_FORMAT linux_printf_pointer_format
diff --git a/gcc/targhooks.c b/gcc/targhooks.c
index d75650f..c7977be 100644
--- a/gcc/targhooks.c
+++ b/gcc/targhooks.c
@@ -1523,6 +1523,22 @@ default_printf_pointer_format (tree, const char **flags)
   return "%zx";
 }
 
+/* For Glibc and uClibc targets also define the hook here because
+   otherwise it would have to be duplicated in each target's .c file
+   (such as in bfin/bfin.c and c6x/c6x.c, etc.)
+   Glibc and uClibc format pointers as if by "%zx" except for the null
+   pointer which outputs "(nil)".  It ignores the pound ('#') format
+   flag but interprets the space and plus flags the same as in the integer
+   directive.  */
+
+const char*
+linux_printf_pointer_format (tree arg, const char **flags)
+{
+  *flags = " +";
+
+  return arg && integer_zerop (arg) ? "(nil)" : "%#zx";
+}
+
 tree
 default_builtin_tm_load_store (tree ARG_UNUSED (type))
 {
diff --git a/gcc/targhooks.h b/gcc/targhooks.h
index 3356f0a..afb1c00 100644
--- a/gcc/targhooks.h
+++ b/gcc/targhooks.h
@@ -192,7 +192,7 @@ extern bool no_c99_libc_has_function (enum function_class);
 extern bool gnu_libc_has_function (enum function_class);
 
 extern const char* default_printf_pointer_format (tree, const char **);
-extern const char* gnu_libc_printf_pointer_format (tree, const char **);
+extern const char* linux_printf_pointer_format (tree, const char **);
 extern const char* solaris_printf_pointer_format (tree, const char **);
 
 extern tree default_builtin_tm_load_store (tree);

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] add uClibc target hook (PR bootstrap/77819)
  2016-10-04 20:25       ` Martin Sebor
@ 2016-10-05 10:38         ` Bernd Schmidt
  0 siblings, 0 replies; 6+ messages in thread
From: Bernd Schmidt @ 2016-10-05 10:38 UTC (permalink / raw)
  To: Martin Sebor, Gcc Patch List

On 10/04/2016 10:25 PM, Martin Sebor wrote:
>
> Sounds good.  Attached is an updated patch reflecting these changes.
> Restested by building the powerpc64-linux and tic6x-uclinux cross
> toolchains.  (Sharing the Glibc and uClibc implementation of the
> target hook and defining it in targhooks.c also obviates the patch
> I sent in for bug 77837 last night so it seems like a win-win.)

Ok.


Bernd

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-10-05 10:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-02 22:02 [PATCH] add uClibc target hook (PR bootstrap/77819) Martin Sebor
2016-10-04  8:42 ` Bernd Schmidt
2016-10-04 14:34   ` Martin Sebor
2016-10-04 14:54     ` Bernd Schmidt
2016-10-04 20:25       ` Martin Sebor
2016-10-05 10:38         ` Bernd Schmidt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).