arm-none-eabi-gcc生成FDPIC ELF二进制文件所需的标志是什么?

huangapple go评论102阅读模式
英文:

What flags are needed in arm-none-eabi-gcc to produce FDPIC ELF binary?

问题

  1. 如何添加以下标志:
  2. arm-none-eabi-gcc test.c -o test -mcpu=cortex-m4 -Wall -Os
  3. 以获取FDPIC二进制文件?
  4. 我进行了许多实验,仍然收到无效格式的消息。我知道有关链接器标志的存在:
  5. --oformat elf32-littlearm-fdpic
  6. 但我不知道如何正确传递它们。
  7. 将编译和链接拆分为两个步骤:
  8. arm-none-eabi-gcc -c test.c -o test.o -mcpu=cortex-m4 -Wall -Os
  9. arm-none-eabi-ld test.o --oformat elf32-littlearm-fdpic -pie -o test
  10. 结果是没有添加新库并产生了关于启动的警告:
  11. arm-none-eabi-ld: warning: cannot find entry symbol _start; defaulting to 0000000000000074
  12. **谁能帮助我?什么是正确的命令(标志)?**
  13. **我想在“裸机”Linux内核上启动我的程序(我已经在那个STM32上编译了工作内核)。我将它交付在内核中编译的initramfs中**
  14. 编辑:
  15. arm-none-eabi-gcc test.c -o test -mcpu=cortex-m4 -Wall -fpic -fpie -Os -Xlinker "--oformat elf32-littlearm-fdpic"
  16. 结果:
  17. /usr/lib/gcc/arm-none-eabi/10.3.1/../../../arm-none-eabi/bin/ld: unrecognized option '--oformat elf32-littlearm-fdpic'
  18. /usr/lib/gcc/arm-none-eabi/10.3.1/../../../arm-none-eabi/bin/ld: use the --help option for usage information
  19. collect2: error: ld returned 1 exit status
  20. make: *** [Makefile:5: all] Error 1
  21. -----------------------------------------------------------------
  22. **此外,这似乎有效(但我想使用启动文件):**
  23. Makefile
  24. all:
  25. arm-none-eabi-as -mcpu=cortex-m4 init.S -o init.o
  26. arm-none-eabi-gcc -c -fpic -Os -mcpu=cortex-m4 -fpie -Wall init.c -o init-c.o
  27. arm-none-eabi-ld init.o init-c.o --oformat elf32-littlearm-fdpic -pie -o init --thumb-entry=_start
  28. init.c
  29. #define USART1_DR (*((volatile unsigned int *)0x40011004))
  30. int main()
  31. {
  32. volatile int i;
  33. USART1_DR = 'A';
  34. for (i = 0; i < 1000000; i++) {
  35. }
  36. USART1_DR = 'B';
  37. while (1) {}
  38. return 0;
  39. }
  40. init.S
  41. .syntax unified
  42. .cpu cortex-m4
  43. .thumb
  44. .global _start
  45. _start:
  46. bl main
  47. b .

注意:以上内容是您提供的信息的翻译,不包括代码部分。如果您需要进一步的帮助或解释,请随时提出。

英文:

what flags do i need to add to:

  1. arm-none-eabi-gcc test.c -o test -mcpu=cortex-m4 -Wall -Os

to get FDPIC binary ?

I made many experiments, and still i receive not a valid format. I know about existence of linker flags:

  1. --oformat elf32-littlearm-fdpic

but i don't know how to pass them properly.

Spliting compiling and linking into separate steps:

  1. arm-none-eabi-gcc -c test.c -o test.o -mcpu=cortex-m4 -Wall -Os
  2. arm-none-eabi-ld test.o --oformat elf32-littlearm-fdpic -pie -o test

Result in that no newlib is added and warning about start is produced:

  1. arm-none-eabi-ld: warning: cannot find entry symbol _start; defaulting to 0000000000000074

Who can help me ? What is the correct commands (flags) ?

I want to start my program on "bare" linux kernel (i have already working kernel on that stm32). I deliver it in initramfs compiled in kernel

EDIT:

  1. arm-none-eabi-gcc test.c -o test -mcpu=cortex-m4 -Wall -fpic -fpie -Os -Xlinker &quot;--oformat elf32-littlearm-fdpic&quot;

Results:

  1. /usr/lib/gcc/arm-none-eabi/10.3.1/../../../arm-none-eabi/bin/ld: unrecognized option &#39;--oformat elf32-littlearm-fdpic&#39;
  2. /usr/lib/gcc/arm-none-eabi/10.3.1/../../../arm-none-eabi/bin/ld: use the --help option for usage information
  3. collect2: error: ld returned 1 exit status
  4. make: *** [Makefile:5: all] Error 1

MOREOVER this tends to work (but i want to use start files):

Makefile:

  1. all:
  2. arm-none-eabi-as -mcpu=cortex-m4 init.S -o init.o
  3. arm-none-eabi-gcc -c -fpic -Os -mcpu=cortex-m4 -fpie -Wall init.c -o init-c.o
  4. arm-none-eabi-ld init.o init-c.o --oformat elf32-littlearm-fdpic -pie -o init --thumb-entry=_start

init.c:

  1. #define USART1_DR (*((volatile unsigned int *)0x40011004))
  2. int main()
  3. {
  4. volatile int i;
  5. USART1_DR = &#39;A&#39;;
  6. for (i = 0; i &lt; 1000000; i++) {
  7. }
  8. USART1_DR = &#39;B&#39;;
  9. while (1) {}
  10. return 0;
  11. }

init.S:

  1. .syntax unified
  2. .cpu cortex-m4
  3. .thumb
  4. .global _start
  5. _start:
  6. bl main
  7. b .

I mean compilation commands. I know my code snippet works only because STM32 has no MMU (and i configured kernel not to use MPU).

答案1

得分: 1

arm-none-eabi-gcc 用于构建在裸机环境中运行的东西,没有涉及操作系统。从快速搜索来看,FDPIC 似乎是用于在没有 MMU 的平台上加载共享库的 ABI。

如果我没有弄错,你不能在裸机环境中加载共享库,因此问题可能是你正在使用错误的编译器构建?

英文:

arm-none-eabi-gcc is for building things that run on bare-metal, with no OS involved. From a quick search FDPIC seems to be an ABI for loading shared libraries in platforms with no MMU.

If I'm not mistaken, you can't load shared libraries in bare-metal environments, thus maybe the problem is that you're building with the wrong compiler?

huangapple
  • 本文由 发表于 2023年6月18日 19:12:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76500242.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定