Issue with combining section alignment and target memory region in ld linker script

Ronald De Keulenaer ronald.dekeulenaer@elis.ugent.be
Mon Jul 4 12:40:00 GMT 2016


Hello,


I'm having some problems with a custom linker script for ld that I'm  
working on, and I was wondering if anyone could show me the correct  
way to do what I'm trying to do.

I have the following somewhere in the SECTIONS part of my linker script:

...
.some_text ALIGN(0x4000) : {
    *a_first_object_file.o(.text)
    *a_first_object_file.o(.text.*)
    *a_second_object_file.o(.text)
    *a_second_object_file.o(.text.*)
} > some_memory_region
...

When I try and use this, I get some errors like this:

ld: address 0x260 of elf-file.elf section `.some_text' is not within  
region `some_memory_region'

Now, what I WANT is to align the .some_text section to the next  
available address in some_memory_region that is aligned to 0x400.  
However, from what I understand, 'ALIGN' is not necessarily compatible  
with '> memory_region'.

I've already tried the following alternative solutions:
1. changing ALIGN to BLOCK (causes the same errors)
2. .some_text : {
      . = ALIGN(0x4000);
      *a_first_object_file.o(.text)
      *a_first_object_file.o(.text.*)
      *a_second_object_file.o(.text)
      *a_second_object_file.o(.text.*)
    } > some_memory_region
    This is a step in the right direction, because the first  
instruction in the some_text section will be
    aligned as I want. However, from objdump output, I still see the  
section itself starting at a non-aligned
    address.
3. insert an empty dummy section as such:
    .dummy : {} > some_memory_region
    right before the .some_text section (in the ld linker script), in  
hopes that I can define .some_text as
    follows:
    .some_text ALIGN(0x4000) : {
      *a_first_object_file.o(.text)
      *a_first_object_file.o(.text.*)
      *a_second_object_file.o(.text)
      *a_second_object_file.o(.text.*)
    }
    , without having to define a target memory region, in other words.
    This doesn't work either, as the section is aligned but not in the  
desired target memory region.

What is the correct way to achieve what I want? I'm sure it's  
possible, and not too hard, but I can't seem to figure it out myself.

Thanks in advance for any and all help!


Best regards,

Ronald De Keulenaer



More information about the Binutils mailing list