Reputation: 11
I have a c source file with lots of global variables, and i want to build a object file with these global Variables in a specific section. add __attribute__((section("section-name")))
for each variable is a large work, except add one by one,how can i build these variables to a specific section?
Upvotes: 1
Views: 67
Reputation: 180145
The easiest solution would be objcopy --rename-section
afterwards. Another option is a linker script:
SECTIONS {
.YourSection { YourFile.c(COMMON) }
}
Upvotes: 0
Reputation: 16426
You could make your global variables members of one or several global structs instead. You might also want to consider your design and whether you really need to have a large number of global variables. Finally ... consider what you're actually trying to achieve; you haven't provided a reason why they should all be in a specific section.
Upvotes: 1