0

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).

arye
  • 458
  • 3
  • 15

2 Answers2

1
  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.

Andrés
  • 51
  • 3
  • can you please give example of one porting, or it is just a compiler flag? even some entry point that I can search from there will be helpful I am still not so familiar with ARM assembly to find it by myself. – arye Oct 15 '20 at 08:38
  • For example in position independent code for Cortex-M, R9 is used as base register for the data area. The compiler will make all accesses relative to the base register and the base register will be setup during module initialization. – Andrés Oct 16 '20 at 09:11
0

@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.

Siva Shanmugam
  • 662
  • 9
  • 19
  • Hi Scott, as far as I understand the modules code, I don't need position independent code if I am using in-place loading to module. Am I wrong? – arye Oct 18 '20 at 09:55
  • 1
    True, you don't need position independent code, just data, if loading in place. – Scott Larson Oct 21 '20 at 03:55