0

I want to enclose an entire C file in a output section,

Here is the example code I am trying:

#include<stdio.h>
#pragma arm section code = ".sec_ro"
int main(void)
{
printf("Hi\n");
}
#pragma arm section

I used :

arm-none-linux-gnueabi-gcc -S hello.c

to get the .S file.

But it looks like the sec_ro section is not present in the .S file.

EDIT/UPDATE :

Attaching the .s file contents :

.arch armv5te
.fpu softvfp
.eabi_attribute 20, 1
.eabi_attribute 21, 1
.eabi_attribute 23, 3
.eabi_attribute 24, 1
.eabi_attribute 25, 1
.eabi_attribute 26, 2
.eabi_attribute 30, 6
.eabi_attribute 18, 4
.file   "hello.c"
.section    .rodata
.align  2
.LC0:
    .ascii  "Hi\000"
    .text
    .align  2
    .global main
    .type   main, %function
main:
    .fnstart
.LFB0:
    @ args = 0, pretend = 0, frame = 0
    @ frame_needed = 1, uses_anonymous_args = 0
    stmfd   sp!, {fp, lr}
    .save {fp, lr}
    .setfp fp, sp, #4
    add fp, sp, #4
    ldr r0, .L2
    bl  puts
    mov r0, r3
    ldmfd   sp!, {fp, pc}

I want to enclose an entire C file to create an output section , I am using GNU ARM tool chain, Am I missing something ?

user2807984
  • 23
  • 2
  • 7

2 Answers2

0

'#pragma arm' directives are only supported with the ARM toolchain (RVCT or DS-5). For GCC you'll need to use a linker script or '_attribute(section)' style syntax. This is supported by both armcc and GCC:

http://www.keil.com/support/man/docs/armccref/armccref_Cacbgief.htm

Pete Fordham
  • 2,278
  • 16
  • 25
  • So it means , if we have a big C file with lets say 100 functions and if we need to place it the entire section then we need to put this 'attirbute(section)' for each and every fucntion ? – user2807984 Sep 24 '13 at 04:16
  • Yes, or you can use a linker script. Google 'linker script gnu LD' for more info. – Pete Fordham Sep 24 '13 at 06:45
  • I am using the linker script , but first the sections should be generated by gcc then ld can find the sections right ? – user2807984 Sep 24 '13 at 08:27
  • You can use the name of the object file in the linker script to direct its content into a particular section. http://www.math.utah.edu/docs/info/ld_3.html#SEC16 – Pete Fordham Sep 24 '13 at 16:01
0

Does that say if use gcc, there is no way to specify entire file session by something like progma?

It is important to allow the progma syntax from source code level, as in many cases, the linker doesnot really know what files are going to be included, especially in a large scale project shares same link script.

yunfei
  • 526
  • 2
  • 6
  • 20