1

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

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

  • test.c - 数据转换函数
  • test_main.c - 调用 start.S 中定义的函数
  • start.S - 在 test.c 中调用一个函数并且还包含 _start

我使用以下方法编译文件:

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 调用中缺少哪些标志、参数等?

4

0 回答 0