threadx module allocating module data section in run time

195 Views Asked by At

I see that when loading threadx module, the data section is allocated in run time from byte pool (at _txm_module_manager_internal_load).

  1. Is there a way to define in advance (in the module preamble or such) the place where the module data will be located?

  2. How dose the module code knows where its globals are located? the compiler can't know their addresses because the place of the data is determined at run time (I suppose somewhere in the assembly porting there is some relative address to the data section that changes for each module that the globals are accessed through it, but I am not so familiar with arm assembly to find it by myself).

2

There are 2 best solutions below

2
On BEST ANSWER
  1. The location of data for each module is determined at run-time. This is to allow loading the same module more than once, each instance having separate data, in different locations.

  2. Globals are located in the data area. The modules are compiled as position independent code and position independent data. While loading the module the module startup code is provided with the load address of the data. The specifics of how this is achieved are different for each architecture and compiler.

2
On

@Andrés has answered correctly, but I wanted to add some info. You must build a Module with position independent code and data (e.g. ROPI and RWPI options if using the ARM compilers). The GCC options look like below (I bolded the relevant compiler options needed for position independence):

arm-none-eabi-gcc -c -g -mcpu=cortex-m4 **-fpie -fno-plt -mpic-data-is-text-relative -msingle-pic-base** txm_module_preamble.s

Let us know if you have further questions.