* Output sections
@ 2009-07-18 8:49 Mohamed Shafi
2009-07-18 11:48 ` Dave Korn
0 siblings, 1 reply; 7+ messages in thread
From: Mohamed Shafi @ 2009-07-18 8:49 UTC (permalink / raw)
To: GCC
Hello all,
Is it possible to emit a assembler directive at the end of each sections?
Say like section_end
Is there any support for doing something like this in the back-end files?
Or should i need to the make changes in the gcc sources?
Is so do does anyone know in which function it should happen?
Regards,
Shafi
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Output sections
2009-07-18 8:49 Output sections Mohamed Shafi
@ 2009-07-18 11:48 ` Dave Korn
2009-07-31 13:42 ` Mohamed Shafi
0 siblings, 1 reply; 7+ messages in thread
From: Dave Korn @ 2009-07-18 11:48 UTC (permalink / raw)
To: Mohamed Shafi; +Cc: GCC
Mohamed Shafi wrote:
> Hello all,
>
> Is it possible to emit a assembler directive at the end of each sections?
> Say like section_end
> Is there any support for doing something like this in the back-end files?
> Or should i need to the make changes in the gcc sources?
> Is so do does anyone know in which function it should happen?
There isn't really such a concept as 'end of a section' until you get to
final-link time and get all the contributions from different .o files to a
given section. During assembler output GCC treats sections as random access,
switching freely from one to another and back; it doesn't have any concept of
starting/stopping/opening/closing a section but just jumps into any one it
likes completely ad-hoc.
Assuming you're happy with adding something to the end of each section in
each generated .s file, you could use the TARGET_ASM_FILE_END hook to output
directives that re-enter each used section and then output your new directive.
You may find it hard to know which sections have been used or not in a given
file - you can define TARGET_ASM_NAMED_SECTION and make a note of which
sections get invoked there, but I'm not sure if that gets called for all
sections e.g. init/fini, you may have to try it and see.
cheers,
DaveK
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Output sections
2009-07-18 11:48 ` Dave Korn
@ 2009-07-31 13:42 ` Mohamed Shafi
2009-08-01 6:24 ` Dave Korn
0 siblings, 1 reply; 7+ messages in thread
From: Mohamed Shafi @ 2009-07-31 13:42 UTC (permalink / raw)
To: Dave Korn; +Cc: GCC
2009/7/18 Dave Korn <dave.korn.cygwin@googlemail.com>:
> Mohamed Shafi wrote:
>> Hello all,
>>
>> Is it possible to emit a assembler directive at the end of each sections?
>> Say like section_end
>> Is there any support for doing something like this in the back-end files?
>> Or should i need to the make changes in the gcc sources?
>> Is so do does anyone know in which function it should happen?
>
> There isn't really such a concept as 'end of a section' until you get to
> final-link time and get all the contributions from different .o files to a
> given section. During assembler output GCC treats sections as random access,
> switching freely from one to another and back; it doesn't have any concept of
> starting/stopping/opening/closing a section but just jumps into any one it
> likes completely ad-hoc.
>
> Assuming you're happy with adding something to the end of each section in
> each generated .s file, you could use the TARGET_ASM_FILE_END hook to output
> directives that re-enter each used section and then output your new directive.
> You may find it hard to know which sections have been used or not in a given
> file - you can define TARGET_ASM_NAMED_SECTION and make a note of which
> sections get invoked there, but I'm not sure if that gets called for all
> sections e.g. init/fini, you may have to try it and see.
>
I am looking for adding something to the end of each section in the
generated .s file. Using TARGET_ASM_NAMED_SECTION i will be able to
keep track of the sections that are being emitted. But from
TARGET_ASM_FILE_END hook how can i re-enter into each section. Are the
sections stored in some global variable?
Shafi
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Output sections
2009-07-31 13:42 ` Mohamed Shafi
@ 2009-08-01 6:24 ` Dave Korn
2009-08-01 6:37 ` Mohamed Shafi
0 siblings, 1 reply; 7+ messages in thread
From: Dave Korn @ 2009-08-01 6:24 UTC (permalink / raw)
To: Mohamed Shafi; +Cc: Dave Korn, GCC
Mohamed Shafi wrote:
> I am looking for adding something to the end of each section in the
> generated .s file. Using TARGET_ASM_NAMED_SECTION i will be able to
> keep track of the sections that are being emitted. But from
> TARGET_ASM_FILE_END hook how can i re-enter into each section. Are the
> sections stored in some global variable?
I'm not sure I understand the question. You "enter a section" simply by
emitting the correct .section directive into the asm output. You re-enter it by
the same method.
cheers,
DaveK
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Output sections
2009-08-01 6:24 ` Dave Korn
@ 2009-08-01 6:37 ` Mohamed Shafi
2009-08-01 7:08 ` Dave Korn
0 siblings, 1 reply; 7+ messages in thread
From: Mohamed Shafi @ 2009-08-01 6:37 UTC (permalink / raw)
To: Dave Korn; +Cc: GCC
2009/8/1 Dave Korn <dave.korn.cygwin@googlemail.com>:
> Mohamed Shafi wrote:
>> I am looking for adding something to the end of each section in the
>> generated .s file. Using TARGET_ASM_NAMED_SECTION i will be able to
>> keep track of the sections that are being emitted. But from
>> TARGET_ASM_FILE_END hook how can i re-enter into each section. Are the
>> sections stored in some global variable?
>
> I'm not sure I understand the question. You "enter a section" simply by
> emitting the correct .section directive into the asm output. You re-enter it by
> the same method.
>
> cheers,
> DaveK
>
Ok, Then i don't understand your solution.
>> you could use the TARGET_ASM_FILE_END hook to output
>> directives that re-enter each used section and then output your new directive.
if i want to do the following in the assembly output
section .code
.....
.....
......
section_end
you are saying that if i emit a section directive the compiler will
switch to the previously emitted section and then i have to somehow
seek to the end of that section and emit my 'section_end' directive?
Shafi
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Output sections
2009-08-01 6:37 ` Mohamed Shafi
@ 2009-08-01 7:08 ` Dave Korn
2009-08-01 8:02 ` Mohamed Shafi
0 siblings, 1 reply; 7+ messages in thread
From: Dave Korn @ 2009-08-01 7:08 UTC (permalink / raw)
To: Mohamed Shafi; +Cc: Dave Korn, GCC
Mohamed Shafi wrote:
> 2009/8/1 Dave Korn <dave.korn.cygwin@googlemail.com>:
>> Mohamed Shafi wrote:
>>> I am looking for adding something to the end of each section in the
>>> generated .s file. Using TARGET_ASM_NAMED_SECTION i will be able to
>>> keep track of the sections that are being emitted. But from
>>> TARGET_ASM_FILE_END hook how can i re-enter into each section. Are the
>>> sections stored in some global variable?
>> I'm not sure I understand the question. You "enter a section" simply by
>> emitting the correct .section directive into the asm output. You re-enter it by
>> the same method.
> Ok, Then i don't understand your solution.
Ah, it looks like I didn't quite understand your problem.
>>> you could use the TARGET_ASM_FILE_END hook to output
>>> directives that re-enter each used section and then output your new directive.
>
> if i want to do the following in the assembly output
>
> section .code
> .....
> .....
> ......
> section_end
I thought you just wanted to have
.section .code
section_end
.section .data
section_end
... etc. for all used sections, at the very end of the file; after all, all the
contributions to a section get concatenated in the assembler. Now you seem to
be saying that you want to have multiple section_end directives throughout the
file, every time the current section changes.
> you are saying that if i emit a section directive the compiler will
> switch to the previously emitted section and then i have to somehow
> seek to the end of that section and emit my 'section_end' directive?
I think you may need to re-read the assembler manual about sections, you are a
little confused about the concepts. The compiler doesn't really "switch"
anything; the compiler emits ".section" directives, in response to which the
*assembler* switches to emit code in the chosen section. The compiler doesn't
keep track of sections; it just randomly emits directives for whichever one it
wants the assembly output to go into at any given time, according to whether
it's generating the assembly for a function or a variable or other data object.
cheers,
DaveK
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Output sections
2009-08-01 7:08 ` Dave Korn
@ 2009-08-01 8:02 ` Mohamed Shafi
0 siblings, 0 replies; 7+ messages in thread
From: Mohamed Shafi @ 2009-08-01 8:02 UTC (permalink / raw)
To: Dave Korn; +Cc: GCC
2009/8/1 Dave Korn <dave.korn.cygwin@googlemail.com>:
> Mohamed Shafi wrote:
>> 2009/8/1 Dave Korn <dave.korn.cygwin@googlemail.com>:
>>> Mohamed Shafi wrote:
>>>> I am looking for adding something to the end of each section in the
>>>> generated .s file. Using TARGET_ASM_NAMED_SECTION i will be able to
>>>> keep track of the sections that are being emitted. But from
>>>> TARGET_ASM_FILE_END hook how can i re-enter into each section. Are the
>>>> sections stored in some global variable?
>>> I'm not sure I understand the question. You "enter a section" simply by
>>> emitting the correct .section directive into the asm output. You re-enter it by
>>> the same method.
>
>> Ok, Then i don't understand your solution.
>
> Ah, it looks like I didn't quite understand your problem.
>
>>>> you could use the TARGET_ASM_FILE_END hook to output
>>>> directives that re-enter each used section and then output your new directive.
>>
>> if i want to do the following in the assembly output
>>
>> section .code
>> .....
>> .....
>> ......
>> section_end
>
> I thought you just wanted to have
>
> .section .code
> section_end
> .section .data
> section_end
>
> ... etc. for all used sections, at the very end of the file; after all, all the
> contributions to a section get concatenated in the assembler. Now you seem to
> be saying that you want to have multiple section_end directives throughout the
> file, every time the current section changes.
>
>> you are saying that if i emit a section directive the compiler will
>> switch to the previously emitted section and then i have to somehow
>> seek to the end of that section and emit my 'section_end' directive?
>
> I think you may need to re-read the assembler manual about sections, you are a
> little confused about the concepts. The compiler doesn't really "switch"
> anything; the compiler emits ".section" directives, in response to which the
> *assembler* switches to emit code in the chosen section. The compiler doesn't
> keep track of sections; it just randomly emits directives for whichever one it
> wants the assembly output to go into at any given time, according to whether
> it's generating the assembly for a function or a variable or other data object.
>
Ok. will TARGET_NAMED_SECTION get invoked for the normal sections like
text, data, bss ? I tired to include this hook in my code, but the
execution never reaches this hook for the sections.
Shafi
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2009-08-01 8:02 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-18 8:49 Output sections Mohamed Shafi
2009-07-18 11:48 ` Dave Korn
2009-07-31 13:42 ` Mohamed Shafi
2009-08-01 6:24 ` Dave Korn
2009-08-01 6:37 ` Mohamed Shafi
2009-08-01 7:08 ` Dave Korn
2009-08-01 8:02 ` Mohamed Shafi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).