How to set alignment and READONLY of a brand new section

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

 



Hi,
I apologize in advance if this is not the right place for this question.

In a software project of mine, on linux, I need to create a special section
that needs to be populated with 40 bytes large structures. Then I would
like to treat this section as an array.
For that I added this linker script with the -T option:

SECTIONS
{
     /* section for CLI cmd array */
    .CLI_cmd_section : ALIGN(8)
    {
        PROVIDE(__CLI_cmd_start = .);
        KEEP(*(.CLI_cmd*));
       . = ALIGN(8) ;
        PROVIDE(__CLI_cmd_end = .);
    }
}
INSERT AFTER .data;

Though, inspecting with objdump I see that the section is aligned to 32
bytes:

Sections:
Idx Name               Size      VMA               LMA               File
off  Algn  Flags
[...]
 25 .data              00000008  0000000000009000  0000000000009000
 00008000  2**3  CONTENTS, ALLOC, LOAD, DATA
 26 .CLI_cmd_section   00000068  0000000000009020  0000000000009020
 00008020  2**5  CONTENTS, ALLOC, LOAD, DATA
 27 .bss               00000078  00000000000090a0  00000000000090a0
 00008088  2**5  ALLOC
[...]

I thought it might be because some of the adjacent sections have such
alignment, but even moving it doesn't change

Sections:
Idx Name               Size      VMA               LMA               File
off  Algn  Flags
[...]
 23 .dynamic           000001f0  0000000000008cf0  0000000000008cf0
 00007cf0  2**3  CONTENTS, ALLOC, LOAD, DATA
 24 .CLI_cmd_section   00000068  0000000000008ee0  0000000000008ee0
 00007ee0  2**5  CONTENTS, ALLOC, LOAD, DATA
 25 .got               000000a8  0000000000008f48  0000000000008f48
 00007f48  2**3  CONTENTS, ALLOC, LOAD, DATA
 26 .data              00000008  0000000000009000  0000000000009000
 00008000  2**3  CONTENTS, ALLOC, LOAD, DATA
[...]

I wanted to try to see what happened to impose a higher alignment (64) and
in this case it sets it. So it seems that for some reason right now I can't
get below 32 on that section.

this is very annoying, because in the array the compiler considers the
entries offset by 40 bytes, while the linker has them offset by 64 bytes.

How should I get my array indexed well, and then impose alignment 8?

Also I would like this section to be READONLY, but if I try to impose it I
get a warning on the link which I don't know how "serious" it is:

/usr/bin/ld: /tmp/ccDmg9Dd.o: warning: relocation in read-only section
`.CLI_cmd.__CLI_cmd_help'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE

Is there a safe, reliable and "clean" way to impose READONLY the
.CLI_cmd_section without having errors/warning from the linker?

best regard
Max


-- 
Et nunc, auxilium solis, vincam!
Oppugnatio solaris!
VIS!

Massimiliano Cialdi



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux