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

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

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

问题

如何添加以下标志:

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

以获取FDPIC二进制文件?

我进行了许多实验,仍然收到无效格式的消息。我知道有关链接器标志的存在:

    --oformat elf32-littlearm-fdpic

但我不知道如何正确传递它们。

将编译和链接拆分为两个步骤:

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

结果是没有添加新库并产生了关于启动的警告:

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

**谁能帮助我?什么是正确的命令(标志)?**

**我想在“裸机”Linux内核上启动我的程序(我已经在那个STM32上编译了工作内核)。我将它交付在内核中编译的initramfs中**

编辑:

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

结果:

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

-----------------------------------------------------------------
**此外,这似乎有效(但我想使用启动文件):**

Makefile:

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

init.c:

    #define USART1_DR (*((volatile unsigned int *)0x40011004))
    
    int main()
    {
        volatile int i;
    
        USART1_DR = 'A';
        
        for (i = 0; i < 1000000; i++) {
        }
    
        USART1_DR = 'B';
    
        while (1) {}
        return 0;
    }

init.S:

    .syntax unified
    .cpu cortex-m4
    .thumb
    .global _start
    
    _start:
    bl main
    b .

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

英文:

what flags do i need to add to:

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:

--oformat elf32-littlearm-fdpic

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

Spliting compiling and linking into separate steps:

arm-none-eabi-gcc -c test.c -o test.o -mcpu=cortex-m4 -Wall -Os
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:

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:

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

Results:

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

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

Makefile:

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

init.c:

#define USART1_DR (*((volatile unsigned int *)0x40011004))

int main()
{
	volatile int i;

	USART1_DR = &#39;A&#39;;
	
	for (i = 0; i &lt; 1000000; i++) {
	}

	USART1_DR = &#39;B&#39;;

	while (1) {}
	return 0;
}

init.S:

.syntax unified
.cpu cortex-m4
.thumb
.global _start

_start:
bl main
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:

确定