diff mbox

RFA: PR 68913: Provide weak version of __fread_chk for PR61886 test

Message ID 568FA50C.9070601@redhat.com
State New
Headers show

Commit Message

Nick Clifton Jan. 8, 2016, 12:01 p.m. UTC
Hi Guys,

   OK - how about this reformulation of the pr61886 test ?

   The patch changes references to __fread_chk with references to just 
fread, which I assume will be present in all target runtime libraries. 
I had to add some preprocessor trickery in order to ensure that 
__USER_LABEL_PREFIX__ is correctly prepended to the assembler name of 
the functions, but other than that the test remains the same.  No linker 
funny business this time.

   I have tested this patch with an x86_64 native (whose C runtime does 
include __fread_chk), an ARM cross compiler (using newlib, which does 
not provide __fread_chk) and with a V850 cross compiler (which uses 
newlib and which also defines __USER_LABEL_PREFIX to "_").  Prior to 
Honza's r231548 patch all three toolchains fail this patched test. 
Using today#s latest and greatest mainline gcc sources, all three 
toolchains pass the patched test.

   OK to apply ?

Cheers
   Nick

gcc/testsuite/ChangeLog
2016-01-08  Nick Clifton  <nickc@redhat.com>

	PR target/68913
	* gcc.dg/lto/pr61886_0.c: Rename the external function called
	to fread so that it will be found in all target runtimes.


((__warn_unused_result__));
+extern size_t fread_warn (void *__restrict __ptr, size_t __ptrlen, 
size_t __size, size_t __n, FILE *__restrict __stream) __asm__ 
(STRING2(__USER_LABEL_PREFIX__) "fread")      __attribute__ 
((__warn_unused_result__)) __attribute__((__warning__ ("fread called 
with bigger size * nmemb than length " "of destination buffer")));
+
  extern __inline __attribute__ ((__always_inline__)) __attribute__ 
((__gnu_inline__)) __attribute__ ((__artificial__)) __attribute__ 
((__warn_unused_result__))
  size_t
-fread (void *__restrict __ptr, size_t __size, size_t __n,
+local_fread (void *__restrict __ptr, size_t __size, size_t __n,
         FILE *__restrict __stream)
  {
    if (__builtin_object_size (__ptr, 0) != (size_t) -1)
@@ -17,9 +20,9 @@
        if (!__builtin_constant_p (__size)
            || !__builtin_constant_p (__n)
            || (__size | __n) >= (((size_t) 1) << (8 * sizeof (size_t) / 
2)))
-        return __fread_chk (__ptr, __builtin_object_size (__ptr, 0), 
__size, __n, __stream);
+        return fread (__ptr, __builtin_object_size (__ptr, 0), __size, 
__n, __stream);
        if (__size * __n > __builtin_object_size (__ptr, 0))
-        return __fread_chk_warn (__ptr, __builtin_object_size (__ptr, 
0), __size, __n, __stream);
+        return fread_warn (__ptr, __builtin_object_size (__ptr, 0), 
__size, __n, __stream);
      }
  }

@@ -28,6 +31,6 @@
  int main ()
  {
    char file_contents[4096];
-  /* We shouldn't get this resolved to a call to __fread_chk_warn.  */
-  return fread (file_contents, 1, nmemb, fp);
+  /* We shouldn't get this resolved to a call to fread_warn.  */
+  return local_fread (file_contents, 1, nmemb, fp);
  }

Comments

Jeff Law Jan. 9, 2016, 12:10 a.m. UTC | #1
On 01/08/2016 05:01 AM, Nick Clifton wrote:
> Hi Guys,
>
>    OK - how about this reformulation of the pr61886 test ?
>
>    The patch changes references to __fread_chk with references to just
> fread, which I assume will be present in all target runtime libraries. I
> had to add some preprocessor trickery in order to ensure that
> __USER_LABEL_PREFIX__ is correctly prepended to the assembler name of
> the functions, but other than that the test remains the same.  No linker
> funny business this time.
>
>    I have tested this patch with an x86_64 native (whose C runtime does
> include __fread_chk), an ARM cross compiler (using newlib, which does
> not provide __fread_chk) and with a V850 cross compiler (which uses
> newlib and which also defines __USER_LABEL_PREFIX to "_").  Prior to
> Honza's r231548 patch all three toolchains fail this patched test. Using
> today#s latest and greatest mainline gcc sources, all three toolchains
> pass the patched test.
>
>    OK to apply ?
>
> Cheers
>    Nick
>
> gcc/testsuite/ChangeLog
> 2016-01-08  Nick Clifton  <nickc@redhat.com>
>
>      PR target/68913
>      * gcc.dg/lto/pr61886_0.c: Rename the external function called
>      to fread so that it will be found in all target runtimes.
Ok.

Thanks for going the extra mile on this one.

jeff
diff mbox

Patch

Index: gcc/testsuite/gcc.dg/lto/pr61886_0.c
===================================================================
--- gcc/testsuite/gcc.dg/lto/pr61886_0.c	(revision 232157)
+++ gcc/testsuite/gcc.dg/lto/pr61886_0.c	(working copy)
@@ -4,12 +4,15 @@ 
  typedef __SIZE_TYPE__ size_t;
  typedef struct _IO_FILE FILE;

-extern size_t __fread_chk (void *__restrict __ptr, size_t __ptrlen, 
size_t __size, size_t __n, FILE *__restrict __stream) __asm__ ("" 
"__fread_chk")      __attribute__ ((__warn_unused_result__));
-extern size_t __fread_chk_warn (void *__restrict __ptr, size_t 
__ptrlen, size_t __size, size_t __n, FILE *__restrict __stream) __asm__ 
("" "__fread_chk")      __attribute__ ((__warn_unused_result__)) 
__attribute__((__warning__ ("fread called with bigger size * nmemb than 
length " "of destination buffer")));
+#define STRING1(a) #a
+#define STRING2(a) STRING1(a)

+extern size_t fread (void *__restrict __ptr, size_t __ptrlen, size_t 
__size, size_t __n, FILE *__restrict __stream) __asm__ 
(STRING2(__USER_LABEL_PREFIX__) "fread")      __attribute__