STM32,位置无关代码 - 不在GOT中的函数指针?

Rob*_*ček 7 gcc arm stm32 position-independent-code

我需要一个在STM32F401上工作的位置无关代码(PIC).但是我对指向例如struct中使用的函数的指针有问题.

简短的例子:

struct process {
  struct process *next;
  const char *name;
  PT_THREAD((* thread)(struct pt *, process_event_t, process_data_t));
  struct pt pt;
  unsigned char state, needspoll;
};

process etimer_process...

static void call_process(struct process *p, process_event_t ev, process_data_t data) {
  int ret;
  ret = p->thread(&p->pt, ev, data);
}
Run Code Online (Sandbox Code Playgroud)

反汇编后:

Disassembly of section .data:
   ...
 20000768 <etimer_process>:
 20000768:  00000000    andeq   r0, r0, r0
 2000076c:  0803b134    stmdaeq r3, {r2, r4, r5, r8, ip, sp, pc}
 20000770:  08027435    stmdaeq r2, {r0, r2, r4, r5, sl, ip, sp, lr}
 20000774:  00000000    andeq   r0, r0, r0
   ...

Disassembly of section .text:
   ...
 8027da4:   68fb        ldr r3, [r7, #12]  //R3 = 0x20000768
 8027da6:   689b        ldr r3, [r3, #8]   //R3 = 0x8027435
   ...
 8027db2:   4798        blx r3  //Branch to R3
   ...
Run Code Online (Sandbox Code Playgroud)

对于偏移量不等于0的代码,R3中的分支地址是错误的.我在这里看不到使用GOT.这是一个错误或缺少编译器/链接器选项?


我可能成功解决的事情:

  • GOT修正
  • 中断表修复
  • Newlib使用适当的cflags编译

二手CFLAGS:

-mlittle-endian -mthumb -mthumb-interwork -mcpu = cortex-m4 -fsingle-precision-constant -Wdouble-promotion -msoft-float -fpic -msingle-pic-base -mpic-data-is-text-relative -mpic -register = r10 -Wno-strict-aliasing -lc

和链接

-fpic

yug*_*ugr 0

这种情况下不需要使用GOT。相反,编译器将添加一个运行时重定位,它将指示动态链接器etimer_process.thread在启动时进行修补(我假设它是在 的定义时初始化的etimer_process)。