This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: Possible bug; code-block vanishes when adding one assembler-instruction.
- From: Richard Sandiford <rdsandiford at googlemail dot com>
- To: Jens Bauer <jens-lists at gpio dot dk>
- Cc: Andreas Schwab <schwab at linux-m68k dot org>, binutils at sourceware dot org
- Date: Fri, 10 May 2013 10:42:25 +0100
- Subject: Re: Possible bug; code-block vanishes when adding one assembler-instruction.
- References: <20130507122903314912 dot 0457de47 at gpio dot dk> <87sj1xv0bs dot fsf at talisman dot default> <20130508213144132481 dot 9400973e at gpio dot dk> <877gj83448 dot fsf at sandifor-thinkpad dot stglab dot manchester dot uk dot ibm dot com> <20130509113822748942 dot 6df40120 at gpio dot dk> <87sj1w1nt4 dot fsf at sandifor-thinkpad dot stglab dot manchester dot uk dot ibm dot com> <20130509203639970923 dot 8532796d at gpio dot dk> <874nebhoud dot fsf at hase dot home> <20130509230759849349 dot 2f104060 at gpio dot dk>
Jens Bauer <jens-lists@gpio.dk> writes:
> Hi Andreas and Richard.
>
> On Thu, 09 May 2013 22:37:14 +0200, Andreas Schwab wrote:
>> Jens Bauer <jens-lists@gpio.dk> writes:
>>
>>> Hmm.. I get an error, when I try to build the code with...
>>> .section .fastcode, "ax", @progbits
>>> ...It doesn't like the extra parameters:
>>
>> arm uses @ as the comment character, replace it by %.
Sorry, I should have remembered that.
> Thank you very much, Andreas, this has been very valuable for me in
> narrowing down the problem.
> I just tried using...
> .section .fastcode,"ax",%progbits
> ...And I got it to build, plus the entire code-block including LDR and
> STR is now placed correctly in SRAM.
Good! This is the right fix btw, rather than a workound. Still...
> Richard, I think you now have a much better idea of what is going on, am
> I right ?
...yeah. The problem is that plain ".section .foo" creates a section
without the SHF_ALLOC flag. In the working .elf file, the section gets
marked allocatable by the linker:
[ 2] .fastcode PROGBITS 10000000 010000 00000c 00 A 0 0 2
which in turn causes .fastcode to be included in the .hex file. In the
broken .elf file, the flag stays clear:
[ 2] .fastcode PROGBITS 10000000 008400 00000c 00 0 0 2
and so .fastcode isn't included in the .hex file.
The difference comes from whether the alignment in:
. = ALIGN (4);
_efastcode = . ;
actually does anything or not. If the address is already correctly
aligned, because the size of the input .fastcode section is divisible by 4,
the section stays unallocatable. If the assignment to "." increases the
address (inserts padding) then the section becomes allocatable.
2-byte instructions like "str r1, [r0, #0]" cause the input .fastcode
section to be exactly 12 bytes long, so no padding is needed and the
section isn't included. Removing the instruction, or inserting a 4-byte
instruction like "str r1, [r0, #200]", causes .fastcode to be 10 or 14
bytes long respectively, so alignment is needed and the section is included.
This behaviour actually seems to be deliberate:
case lang_data_statement_enum:
/* Make sure that any sections mentioned in the expression
are initialized. */
exp_init_os (s->data_statement.exp);
/* The output section gets CONTENTS, ALLOC and LOAD, but
these may be overridden by the script. */
flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD;
(i.e. you have to use something like INFO in order to preserve the
unallocatable state). It seems really nonobvious though...
Richard