如何用二进制文本在LD中指定名称

How to specify names in LD with binary text?

本文关键字:定名称 LD 何用 二进制 文本      更新时间:2023-10-16

我正试图将一个带有ld的文本文件包装成.o。考虑到我的项目的Makefiles是如何设置的,文本文件的完整路径将传递给ld。这会导致生成的名称包含该路径。我不想这样,因为我不能在C++源代码中链接到那个名字。

当我运行ld时,有没有办法更改名称或前缀?

ld -r -b binary /path/to/source/Value.txt -o Value.o
objdump -x Value.o | grep binary
0000000000000142 g       .data  0000000000000000 _binary__path_to_source_Value_txt_end
0000000000000142 g       *ABS*  0000000000000000 _binary__path_to_source_Value_txt_size
0000000000000000 g       .data  0000000000000000 _binary__path_to_source_Value_txt_start

我希望看到像_binary_Value_txt_end这样的名字。

基于Captain Oblivious的评论,我能够开发一个Makefile规则:

%.o: %.txt
    pushd $(dir $<) ; $(LD) -r -b binary $(notdir $<) -o $@ ; popd

这将更改文本文件的目录位置,以便ld创建漂亮的已知名称。我需要做一些工作来确保$@是一个绝对路径,以便在构建目录中创建.o