[Ltrace-devel] [PATCH 2/2] Fix build for x86_64

Zach Welch zwelch at codesourcery.com
Mon Dec 13 17:53:59 UTC 2010


On 12/13/2010 01:02 AM, Petr Machata wrote:
> 10.12.2010 23:52, Zachary T Welch wrote:
>> Some ELF-related variables differ depending on the native host, so
>> this patch uses conditional compilation tricks to ensure everything
>> works out on each host.
> 
> So how about sticking this to some .h:
> 
> #if __ELF_NATIVE_CLASS == 32
> # define PRI_ELF_size PRIx32
> #else
> # define PRI_ELF_size PRIx64
> #endif
> 
> ... and then using that?

Yeah, I suppose that's worth doing, even though it's only used in a
couple of spots at the moment.

>> @@ -252,7 +258,13 @@ hook_libdl_cb(void *data) {
>>
>>   int
>>   linkmap_init(Process *proc, struct ltelf *lte) {
>> -	void *dbg_addr = NULL, *dyn_addr = (void *)(unsigned)lte->dyn_addr;
>> +	void *dbg_addr = NULL;
>> +	void *dyn_addr =
>> +#if __ELF_NATIVE_CLASS == 32
>> +		(void *)(uint32_t)lte->dyn_addr;
>> +#else
>> +		(void *)(uint64_t)lte->dyn_addr;
>> +#endif
> 
> It's interesting that this one should be necessary.  Isn't unsigned on 
> 32-bit architecture exactly uint32_t and on 64-bit architecture 
> uint64_t?  Or are there conditions where ELF_NATIVE_CLASS is different 
> that the architecture of the build?

In hindsight, I think the cast is only needed on the 32-bit side, as the
lte->dyn_addr field is a GElf_Addr, which is always a 64-bit quantity. I
used the __ELF_NATIVE_CLASS symbol for the sake of consistency in the
patch, but I think you are right to question its appropriateness in this
context.

Incidentally, I feel that there's some way to eliminate this
conditional, but that solution has been eluding me.

-- 
Zach Welch
CodeSourcery
zwelch at codesourcery.com
(650) 331-3385 x743



More information about the Ltrace-devel mailing list