This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: variables order(arrange)


Is there no easier way? Generally, it is very strange. In most
compilers I used earlier variables placed in memory one after another,
in the order they are declared in the program.  Or you had to use some
flag when compiling application. Applied to these solutions.
As far I understand, in order to place a section in the script I need
to know their names. How to find the names of the sections?
04.04.2014 16:07, Jeff Law пишет:
> On 04/04/14 06:19, Man Glory wrote:
>> Is it possible to build such application using gcc to variables
>> arranged in order of their declared in source code?
>> For example, I have 2 variables in application declared one after
>> another, and then build the application, one of them is located at
>> 0x20001330, another at 0x2000131C. In the range between these
>> addresses the compiler placed several other variables. And I would
>> like to see these variables were located in neighboring cells, ie one
>> after another.
>> I looked at the gcc description and found nothing suitable.
> Use -fdata-sections and a linker script.
>
> -fdata-sections will place each variable into its own section (assuming your object format supports that, ELF does).
>
> Once that's in place, you can use a linker script to explicitly place the two sections next to each other.
>
> Jeff
>

2014-04-04 16:07 GMT+03:00 Jeff Law <law@redhat.com>:
> On 04/04/14 06:19, Man Glory wrote:
>>
>> Is it possible to build such application using gcc to variables
>> arranged in order of their declared in source code?
>> For example, I have 2 variables in application declared one after
>> another, and then build the application, one of them is located at
>> 0x20001330, another at 0x2000131C. In the range between these
>> addresses the compiler placed several other variables. And I would
>> like to see these variables were located in neighboring cells, ie one
>> after another.
>> I looked at the gcc description and found nothing suitable.
>
> Use -fdata-sections and a linker script.
>
> -fdata-sections will place each variable into its own section (assuming your
> object format supports that, ELF does).
>
> Once that's in place, you can use a linker script to explicitly place the
> two sections next to each other.
>
> Jeff
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]