How to declare a C array that takes up all the free space in the memory section?

Suppose I have a 128 KB memory area. In my linker directives, I have broken this area into three sections:

  • .section_text
  • .section_data li>
  • .section_bss

The size of each section is unknown precompilation, but I limited .section_bss to use all the remaining space in the memory area after allocating .section_text and .section_data.

Is there a way to declare a C array that uses all the free space in .region_bss? Suppose this is the only one that uses .region_bss so that it can safely use the entire region. For example, goals, but clearly wrong:

char entire_bss[sizeof(.region_bss)];

Here are my preliminary answers to some of the expected answers. Firstly, I know that sizeof () does not work like that. I just use it to get an idea. Secondly, suppose you need to do this with an array, not with pointers (a solution using pointers is possible and quite simple). Thirdly, I know that I can get the start and end addresses of .region_bss, but I don’t know how to use them for my array. At least it doesn't work in C.

It very well cannot be this, but I hope that some genius has figured it out. Extra credit if you can get it working with the Green Hills toolkit.

+3
source share
5

C, .region_bss?

- "".

GreenHills GNU binutils script, , PROVIDE, 128K. (. ). , C , , , , C.

C99, , , .

+2

, , - :

extern char section_bss[];

, , , , section_bss .section_bss ( ).

, , , , bss, .

+2

, . , . .bss .data, . ( , , ), , . , , . - - ( - , 80186, MS-C 5.1, .data (, ), .

, , . , ( ), ( 256 , 512 896 ) . , . malloc/free.

+2

, , . , , extern char the_array [], end_of_array []; C, , , the_array end_of_array. , the_array , , end_of_array , , . - , , , , .

0

extern char __ghsbegin_region_bss[];
extern char __ghssize_region_bss[];
#define entire_bss __ghsbegin_region_bss
#define sizeof_entire_bss ((size_t)__ghssize_region_bss)

? , , ++ ( , entire_bss , , , ). - ( , C), .

, __ghssize_region_bss - ​​ - 100% [...] .

. ", " " ".

0

Source: https://habr.com/ru/post/1765892/


All Articles