I would like to place a symbol into another segment and am running into
great difficulty.  The symbol is uninitialized (and therefore COMMON).

Suppose that there is a symbol thus:

int X[1000];

This normally gets marked as a COMMON symbol and the loader eventually
puts it into .bss at final link time.  If I change the code to look like:

int X[1000] __attributes__((segment(".mybss")));

This has no effect, since the symbol is COMMON and not attached to a segment
yet (or so I presume).  Now, if I add the "nocommon" attribute like this:

int X[1000] __attributes__((nocommon,segment(".mybss")));

I do get the symbol "X" palced into the .mybss segment, but it is
now an initialized variable.  The problem with this is that it makes
the object file quite large for some of the data I need to be using.

If I take the original file, then do a relocatable link with the script:

SECTIONS { .mybss : { *(.bss) } }

I actually do get the symbol put into .mybss.  I'm not quite sure how this
works, but the problem is that I can only move the entire bss segment this
way, and it takes extra post-processing after the compile.  I guess I could
live with that if I really had to, but I'm searching for a better way right
now...

If I look at the object file header produced for the 3rd case (with the
initialized data) I see that .mybss is being created with the CONTENTS,
ALLOC, LOAD, and DATA flags set, which seems appropriate for initialized
data, and in the last case only the ALLOC flag is set.  So, perhaps another
way of saying this is that I would like to put my data into a segment
with only the ALLOC flag set, or change the flags on a segment somehow.

Does anybody have any suggestions on the best way to accomplish this?

marcus hall


marcus

Reply via email to