Common sections

fearyourself fearyourself@gmail.com
Mon Jun 7 14:52:00 GMT 2010


Fair enough. I'll try to explain more.

Basically, I have a segment called bss_big which is the big memory
segment. If I compile two .c files such as :

fct1.c:

long target;
long targeta;

fct2.c:

long target2;
long target2a;

then I get the same address for target and target2. And the same
address for targeta and target2a.

Were I to put this section as SEC_IS_COMMON, it works well and
actually puts the addresses right but then it fails on the archives
problem where if I do :

gcc fct1.c fct2.c -lc -lc, I'll get multiple definitions...

If they are in the regular .bss, they have no problems.

I'll look now for the flag values of .bss and see if I'm missing flags
for these new sections.

If you've got any ideas, it would be much appreciated,
Jc

From what you're saying, clearly SEC_IS_COMMON is not what I'd really
want but I

On Sun, Jun 6, 2010 at 11:45 PM, Ian Lance Taylor <iant@google.com> wrote:
> fearyourself <fearyourself@gmail.com> writes:
>
>> If I declare a new section bss_bigsegment, than it isn't seen as a
>> common section by anybody.
>>
>> Therefore, two different files might have these segments and the
>> linker will set the same base address for each file.
>
> I'm not sure what you mean by "set the same base address", but the
> linker should not merge two sections from different files together;
> they should have different addresses in the generated file.
>
>
>> However, if I declare in the elf_backend_section_flags hook that this
>> section is also a SEC_IS_COMMON, then I get the right addressing.
>
> What object file format are you using?
>
> I gather that you actually want a common section here.  Note that BSS
> sections are not normally common sections.  A BSS section represents
> zero-initialized data.  A common section is used to implement cases
> where the same definition may appear multiple times in different
> object files, and the linker merges them together rather than giving a
> multiple definition error.
>
>
>> However, I then get a weird error when I do:
>>
>> gcc hello.c -lc -lc I get multiple declarations of variables in
>> bss_bigsegment that were defined by newlib.
>
> This suggests that you have non-common symbols defined in a section
> that you want to treat as common.  Unless you are working with Fortran
> programs, this is sufficiently odd that I think you need to explain
> further what you are trying to do.
>
> Ian
>



More information about the Binutils mailing list