在源文件和汇编文件中使用链接时间优化的正确方法?

问题描述

我目前正在为嵌入式系统使用 LTO(以查看它是否可以减小尺寸)并且在直接使用 ld 使所有内容正确链接时遇到了一些问题,并且想知道我做错了什么。在我将其用于更大的项目之前,这主要是在玩玩具程序。

设置基本上是我有 3 个文件

我使用以下方法编译文件

arm-none-eabi-as -mthumb -Wall start.S -o start.o
arm-none-eabi-gcc -Wall -Werror -march=armv7 -mtune=cortex-r7 -mthumb -fPIC -nostdlib -flto -static test.c -c test.o
arm-none-eabi-gcc -Wall -Werror -march=armv7 -mtune=cortex-r7 -mthumb -fPIC -nostdlib -flto -static test_main.c -c test_main.o

如果我然后尝试将程序与 ld 链接,我会得到:

arm-none-eabi-ld --static -fPIC --shared --fatal-warning test.o start.o test_main.o -test
arm-none-eabi-ld: test.o: plugin needed to handle lto object
arm-none-eabi-ld: test.o: plugin needed to handle lto object
arm-none-eabi-ld: test_main.o: plugin needed to handle lto object
arm-none-eabi-ld: test_main.o: plugin needed to handle lto object   

如果我使用 gcc,它可以工作:

arm-none-eabi-gcc -Wall -Werror -march=armv7 -mtune=cortex-r7 -mthumb -fPIC -nostdlib -flto -static test.o start.o test_main.o -o test.gcc

我曾尝试直接指定链接插件,但随后出现不同的错误

arm-none-eabi-ld --static -fPIC --shared --fatal-warning --plugin <path_to_correct>/liblto_plugin.so test.o start.o test_main.o -test
arm-none-eabi-ld: <path_to_correct>.../lto-plugin.c:741: all_symbols_read_handler: Assertion 'lto_wrapper_argv' Failed.
Aborted (core dumped)

我的 ld 调用中缺少哪些标志、参数等?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)