Hi Jeff,
As folks noted, I think this is still specific to the linker in use.
True. :-(
I cannot think of any linker neutral way to add a link time symbol
definition. Any attempts to define the __fread_chk function via an
object file will affects the ipa/lto code and prevent the test from working.
I did have one idea though - we could change the name of the function
being tested from one that might not exist (__fread_chk) to one that
definitely should exist (eg malloc).
Does it make sense to just limit this test to specific platforms,
perhaps just x86/i686 linux for now.
68913 mentions ppc64-linux fails,
it'd be nice to know why since I'd expect that has the _chk symbols.
Actually 68913 references any Solaris target, not ppc64-linux.
We could restrict the test to any target that has the GNU linker. That
would probably cover most targets, and since the actual bug being
checked by the testcase is a generic one, not a target specific one, we
can be reasonably confident that if the problem resurfaces it will be
detected.
So, two possible alternative versions of the patch are proposed below.
Do either take your fancy ?
Cheers
Nick
Index: gcc/testsuite/gcc.dg/lto/pr61886_0.c
===================================================================
--- gcc/testsuite/gcc.dg/lto/pr61886_0.c (revision 232132)
+++ gcc/testsuite/gcc.dg/lto/pr61886_0.c (working copy)
@@ -1,6 +1,11 @@
-/* { dg-lto-do link } */
+/* { dg-lto-do link { target gld } } */
/* { dg-lto-options { { -flto -O2 -Werror } } } */
+/* { dg-extra-ld-options "-Wl,--defsym,__fread_chk=0x1234" { target {
gld } } } */
+/* This test is currently restricted to targets that use the GNU linker.
+ For the reason why see PR68913 and the gcc-patches thread starting here:
+ https://gcc.gnu.org/ml/gcc-patches/2016-01/msg00212.html */
+
typedef __SIZE_TYPE__ size_t;
typedef struct _IO_FILE FILE;
Or....
Index: gcc/testsuite/gcc.dg/lto/pr61886_0.c
===================================================================
--- gcc/testsuite/gcc.dg/lto/pr61886_0.c (revision 232132)
+++ gcc/testsuite/gcc.dg/lto/pr61886_0.c (working copy)
@@ -1,11 +1,10 @@
-/* { dg-lto-do link } */
+/* { dg-lto-do link { target gld } } */
/* { dg-lto-options { { -flto -O2 -Werror } } } */
-
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")));
+extern size_t __malloc (void *__restrict __ptr, size_t __ptrlen, size_t
__size, size_t __n, FILE *__restrict __stream) __asm__ ("")
__attribute__ ((__warn_unused_result__));
+extern size_t __malloc_warn (void *__restrict __ptr, size_t __ptrlen,
size_t __size, size_t __n, FILE *__restrict __stream) __asm__ ("")
__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
@@ -17,9 +16,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 __malloc (__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 __malloc_warn (__ptr, __builtin_object_size (__ptr, 0),
__size, __n, __stream);
}
}
@@ -28,6 +27,6 @@
int main ()
{
char file_contents[4096];
char file_contents[4096];
- /* We shouldn't get this resolved to a call to __fread_chk_warn. */
+ /* We shouldn't get this resolved to a call to __malloc_warn. */
return fread (file_contents, 1, nmemb, fp);
}