public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [testsuite, Android] Add <stdlib.h> to pr56407.c
@ 2013-08-05 10:57 Alexander Ivchenko
  2013-08-05 19:07 ` Maxim Kuvyrkov
  0 siblings, 1 reply; 5+ messages in thread
From: Alexander Ivchenko @ 2013-08-05 10:57 UTC (permalink / raw)
  To: GCC Patches, Maxim Kuvyrkov

Hi,

The following test case fails to compile on Android: gcc.dg/torture/pr56407.c

/tmp/ccA08Isw.o:pr56407.c:function test: error: undefined reference to 'rand'
collect2: error: ld returned 1 exit status

Which is not surprising at all, since the testcase has only the
declarations of abort() and rand()
and doesn't have any headers included.

The following patch adds <stdlib.h> to the test.
Tested on x86_64-unknown-linux-gnu and on Android. Also I checked that
the original regression appears on the fixed test.

Is it OK for trunk?

diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index f356d55..5c23650 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2013-08-05  Alexander Ivchenko  <alexander.ivchenko@intel.com>
+
+       * gcc.dg/torture/pr56407.c: Add include of stdlib.h. Remove
+       declaration of abort() and rand().
+
 2013-08-04  Ed Smith-Rowland  <3dw4rd@verizon.net>

        PR c++/58072
diff --git a/gcc/testsuite/gcc.dg/torture/pr56407.c
b/gcc/testsuite/gcc.dg/torture/pr56407.c
index f26fd23..5d35874 100644
--- a/gcc/testsuite/gcc.dg/torture/pr56407.c
+++ b/gcc/testsuite/gcc.dg/torture/pr56407.c
@@ -1,7 +1,6 @@
 /* { dg-do run } */

-extern void abort(void);
-extern int rand(void);
+#include <stdlib.h>

 static void copy(int *r,int *a,int na)
 {


--Alexander

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

* Re: [testsuite, Android] Add <stdlib.h> to pr56407.c
  2013-08-05 10:57 [testsuite, Android] Add <stdlib.h> to pr56407.c Alexander Ivchenko
@ 2013-08-05 19:07 ` Maxim Kuvyrkov
  2013-08-06 11:58   ` Alexander Ivchenko
  0 siblings, 1 reply; 5+ messages in thread
From: Maxim Kuvyrkov @ 2013-08-05 19:07 UTC (permalink / raw)
  To: Alexander Ivchenko; +Cc: GCC Patches

On 5/08/2013, at 10:57 PM, Alexander Ivchenko wrote:

> Hi,
> 
> The following test case fails to compile on Android: gcc.dg/torture/pr56407.c
> 
> /tmp/ccA08Isw.o:pr56407.c:function test: error: undefined reference to 'rand'
> collect2: error: ld returned 1 exit status
> 
> Which is not surprising at all, since the testcase has only the
> declarations of abort() and rand()
> and doesn't have any headers included.

It *is* surprising given that the testcase does have declarations of abort() or rand() -- which are the only two external functions referenced.

> 
> The following patch adds <stdlib.h> to the test.

I don't think this a correct fix.  [In most such cases the real problem can be found out by examining why linking a test against glibc works, but against bionic -- doesn't.]

How are you linking this testcase?  Please post both the link line from testsuite log and verbose output of linking (obtainable by adding "-v" to the link line).

Thank you,

--
Maxim Kuvyrkov
www.kugelworks.com


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

* Re: [testsuite, Android] Add <stdlib.h> to pr56407.c
  2013-08-05 19:07 ` Maxim Kuvyrkov
@ 2013-08-06 11:58   ` Alexander Ivchenko
  2013-08-06 12:04     ` Andreas Schwab
  0 siblings, 1 reply; 5+ messages in thread
From: Alexander Ivchenko @ 2013-08-06 11:58 UTC (permalink / raw)
  To: Maxim Kuvyrkov, enh; +Cc: GCC Patches

The reason for undefined reference to rand is that it is defined as
"static __inline__" in Bionic stdlib.h:

static __inline__ int rand(void) {
    return (int)lrand48();
}

So in fact, if you do "nm libc.so" for Bionic, you won't get the
rand.. which is probably not correct, because it doesn't have the
external linkage. I added Elliott.

Still, in C standart it is said that rand is defined in stdlib.h, and
we don't include it in that testcase.


thanks,
Alexander


2013/8/5 Maxim Kuvyrkov <maxim@kugelworks.com>:
> On 5/08/2013, at 10:57 PM, Alexander Ivchenko wrote:
>
>> Hi,
>>
>> The following test case fails to compile on Android: gcc.dg/torture/pr56407.c
>>
>> /tmp/ccA08Isw.o:pr56407.c:function test: error: undefined reference to 'rand'
>> collect2: error: ld returned 1 exit status
>>
>> Which is not surprising at all, since the testcase has only the
>> declarations of abort() and rand()
>> and doesn't have any headers included.
>
> It *is* surprising given that the testcase does have declarations of abort() or rand() -- which are the only two external functions referenced.
>
>>
>> The following patch adds <stdlib.h> to the test.
>
> I don't think this a correct fix.  [In most such cases the real problem can be found out by examining why linking a test against glibc works, but against bionic -- doesn't.]
>
> How are you linking this testcase?  Please post both the link line from testsuite log and verbose output of linking (obtainable by adding "-v" to the link line).
>
> Thank you,
>
> --
> Maxim Kuvyrkov
> www.kugelworks.com
>
>

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

* Re: [testsuite, Android] Add <stdlib.h> to pr56407.c
  2013-08-06 11:58   ` Alexander Ivchenko
@ 2013-08-06 12:04     ` Andreas Schwab
  2013-08-06 12:42       ` Alexander Ivchenko
  0 siblings, 1 reply; 5+ messages in thread
From: Andreas Schwab @ 2013-08-06 12:04 UTC (permalink / raw)
  To: Alexander Ivchenko; +Cc: Maxim Kuvyrkov, enh, GCC Patches

Alexander Ivchenko <aivchenk@gmail.com> writes:

> Still, in C standart it is said that rand is defined in stdlib.h, and
> we don't include it in that testcase.

It also says: "Provided that a library function can be declared without
reference to any type defined in a header, it is also permissible to
declare the function and use it without including its associated
header."

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

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

* Re: [testsuite, Android] Add <stdlib.h> to pr56407.c
  2013-08-06 12:04     ` Andreas Schwab
@ 2013-08-06 12:42       ` Alexander Ivchenko
  0 siblings, 0 replies; 5+ messages in thread
From: Alexander Ivchenko @ 2013-08-06 12:42 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Maxim Kuvyrkov, enh, GCC Patches

Thanks Andreas, it seems clear now that Bionic rand function is not
consistent with the standart.


--Alexander

2013/8/6 Andreas Schwab <schwab@suse.de>:
> Alexander Ivchenko <aivchenk@gmail.com> writes:
>
>> Still, in C standart it is said that rand is defined in stdlib.h, and
>> we don't include it in that testcase.
>
> It also says: "Provided that a library function can be declared without
> reference to any type defined in a header, it is also permissible to
> declare the function and use it without including its associated
> header."
>
> Andreas.
>
> --
> Andreas Schwab, SUSE Labs, schwab@suse.de
> GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
> "And now for something completely different."

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

end of thread, other threads:[~2013-08-06 12:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-05 10:57 [testsuite, Android] Add <stdlib.h> to pr56407.c Alexander Ivchenko
2013-08-05 19:07 ` Maxim Kuvyrkov
2013-08-06 11:58   ` Alexander Ivchenko
2013-08-06 12:04     ` Andreas Schwab
2013-08-06 12:42       ` Alexander Ivchenko

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).