This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [testsuite, Android] Add <stdlib.h> to pr56407.c


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]