0

I am facing an issue in creating multiple sections in a .c file. I wants to place code for task1 in section .task1 and code for task2 in section .task2

Consider the following code: case 1:

#include <stdio.h>
/* Variables for task 1 */
int task1_a;
char task1_b;

/* Variables for task 2 */
int task2_a;
char task2_b;

If I use attribute section as below it works fine. case 2:

#include <stdio.h>`
__attribute__ ((section (".task1"))) int task1_a;
__attribute__ ((section (".task1"))) char task1_b;

__attribute__ ((section (".task2"))) int task2_a;
__attribute__ ((section (".task2"))) char task2_b;

but what I want is like: case 3:

#include <stdio.h>
__attribute__ ((section (".task1")))
int task1_a;
char task1_b;

__attribute__ ((section (".task2")))
int task2_a;
char task2_b;

So that all the time we do not need to write attribute ((section (".xyz"))) in front of all the variables or functions.

While compiling case 3 compiler is throwing an error:

error: section of 'task2_a' conflicts with previous declaration
int task2_a

Is there any way to end the section before starting new section. My understanding is that it should automatically end if we start a new section but it is not happening.

I am using arm-unknown-eabi-gcc version 4.8.4 for compilation.

user21096
  • 11
  • 5
  • 2
    `__attribute__` is a part of one declaration only. That's the syntax and you can do nothing about it. Perhaps write some magic macro... – Eugene Sh. Jul 22 '16 at 13:58
  • I have tried to compile your case 3 and no error occured. Maybe you should change your C compiler. – Berkay92 Jul 22 '16 at 14:41
  • 1
    Why not use 2 `.c` files? – a3f Jul 22 '16 at 14:57
  • @a3f I second that. Section targetting is always super fiddly and toolchain (and even version of toolchain dependent). Putting things in separate files can simplify the process and make it less quirky. – Russ Schultz Jul 22 '16 at 18:36
  • Yeah alternative option is to split the code in 2 files but I have seen such code for other platforms like powerpc and mpis. So I wanted to know if this is possible for arm as well. – user21096 Jul 25 '16 at 16:26
  • What is it that you are trying to achieve? You can not just put everything in one section. Some data is read/write and other is read-only so the notation you want won't be available. You can use a macro to make things easier or see [this answer on static shared libraries](http://stackoverflow.com/questions/25172834/how-to-create-static-linked-shared-libraries/25189092#25189092) which maybe what you want. – artless noise Jul 26 '16 at 13:55
  • I am creating Memory Partition such that different applications run all together without interference with each other using MMU. – user21096 Jul 27 '16 at 11:02

0 Answers0