[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Implicition declarations of functions and bugs

"David Mosberger-Tang" <David.Mosberger@acm.org> writes:

> On 3/11/06, Goswin von Brederlow <brederlo@informatik.uni-tuebingen.de> wrote:
>> > $ gcc-3.3 -c -g -O -Wall t.c
>> > t.c: In function `foo':
>> > t.c:4: warning: implicit declaration of function `strdup'
>> > t.c:4: warning: return makes pointer from integer without a cast
>> (all asm is from amd64)
>> 0000000000400500 <foo>:
>>   400500:       48 83 ec 08             sub    $0x8,%rsp
>>   400504:       31 c0                   xor    %eax,%eax
>>   400506:       e8 d5 fe ff ff          callq  4003e0 <strdup@plt>
>>   40050b:       48 83 c4 08             add    $0x8,%rsp
>>   40050f:       48 98                   cltq
>>   400511:       c3                      retq
>> The return value of strdup is passed back unaltered. No crash.
> The context of this discussion was ia64, but I realize now that this
> probably wasn't obvious for debian-devel subscribers.  I should have
> been clear about that.  In any case, ia64 calling convention say that
> a 32-bit integer value in a (64-bit) register may contain garbage in
> the top 32 bits, hence the result from a function returning "int" will
> be sign- or zero-extended when converted to a 64-bit value, hence the
> crash.

Ah, that explains it. On amd64 I believe the callee has to take care
of keeping the top 32bit clean, i.e. return values are already
extended to 64bit. Lucky us.

Still, both original examples are harmfull and should be detected. A
crash is much simpler to detect than lost upper bits so I would
consider detecting the strlen case automaticaly much more
important. I bet the crash will get detected by itself.

By the way, does ia64 NOT map anything into the lower 4GiB address
space like alpha does? In that case any pointer passed as int
segfaults. On amd64 they didn't keep the lower 4GiB free. :(


Reply to: