This is the mail archive of the binutils@sourceware.org mailing list for the binutils 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: [Gold] Question about the incorrect variable alignment if the alignment is greater than the page size


2013/6/4 Ian Lance Taylor <iant@google.com>:
>> -         off = align_file_offset(off, addr, abi_pagesize);
>> +         {
>> +           // Taking care of the case when the maximum segment alignment
>> +           // is larger than the page size.
>> +           uint64_t align = ((*p)->maximum_alignment() < abi_pagesize
>> +                             ? abi_pagesize
>> +                             : (*p)->maximum_alignment());
>> +           off = align_file_offset(off, addr, align);
>> +         }
>
> This is C++.  It should work to simply do
>     off = align_file_offset(off, addr, std::max(abi_pagesize,
> (*p)->maximum_alignment()));

Always forget about that, thanks :) I fixed it.

> In the test, I recommend that rather than using
> large_symbol_alignment.sh you just write your main function to verify
> that the symbols are correctly aligned.  And put a space between the
> right parenthesis and "int".

Done. I had to make artificial volatile variables because gcc always tried to
delete the true "if" branch as a dead code (in O0 as well), eventhough
I check in gdb
that the condition is true:

40|   if ((reinterpret_cast<uintptr_t>(&aligned_16k_var) & 16383) != 0
41|       || (reinterpret_cast<uintptr_t>(&aligned_8k_var) & 8191) != 0
42|       || (reinterpret_cast<uintptr_t>(&aligned_4k_var) & 4095) != 0)
43|       return 1;
44+>  return 0;

(gdb) p (reinterpret_cast<uintptr_t>(&aligned_16k_var) & 16383) != 0
$2 = true

Gcc probably assumes that if the variable been declared with attribute
aligned then it will
certanly have that alignment...

The modifed patch is attached.  All make check-gold test passes for me
on x86_64-unknown-linux-gnu.
Is it ok for trunk? If so, could someone commit please? I don't have
commit access.


Thanks,
Alexander

Attachment: large_alignment_fix_02.patch
Description: Binary data


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