Gcc 与ld和ar命令重叠的内存
我已使用此命令链接了一些文本文件: ld-r-b binary-o resources1.o*.txt 我得到一个包含以下内容的文件resources.o: nm资源1.o 我从另一个ld命令提交了其他resources2.o文件,但它有不同的内容:Gcc 与ld和ar命令重叠的内存,gcc,compilation,ld,unix-ar,hardcoded,Gcc,Compilation,Ld,Unix Ar,Hardcoded,我已使用此命令链接了一些文本文件: ld-r-b binary-o resources1.o*.txt 我得到一个包含以下内容的文件resources.o: nm资源1.o 我从另一个ld命令提交了其他resources2.o文件,但它有不同的内容: 00000018 D _binary___textos1_texto1_txt_end 00000018 A _binary___textos1_texto1_txt_size 00000000 D _binary___textos1_texto1
00000018 D _binary___textos1_texto1_txt_end
00000018 A _binary___textos1_texto1_txt_size
00000000 D _binary___textos1_texto1_txt_start
00000031 D _binary___textos1_texto2_txt_end
00000019 A _binary___textos1_texto2_txt_size
00000018 D _binary___textos1_texto2_txt_start
0000004a D _binary___textos1_texto3_txt_end
00000019 A _binary___textos1_texto3_txt_size
00000031 D _binary___textos1_texto3_txt_start
我想将这两个resources.o文件合并到一个libSum.a文件中。所以我使用这个命令:
ar rvs libSum.a资源1.o资源2.o
当我将libSum.a链接到我的C程序并尝试使用这些文本时,我不能因为它们共享相同的内存偏移量。因此,二进制文本os1\u texto1\u txt\u start的方向与二进制文本4\u txt\u start(0X00000000)的方向相同
如何将两个资源文件合并到一个.a库中以避免内存偏移重叠?
谢谢文件内容有一个愚蠢的错误。它们是同一个文件,名称不同(复制粘贴错误),所以当显示其内容时,似乎是内存偏移错误 现在,我正在使用下一个脚本编译“libResources.a”库中的所有资源: 为了测试硬编码资源,我使用以下C代码:
/*
============================================================================
Name : linkerTest.c
============================================================================
*/
#include <stdio.h>
#include <stdlib.h>
extern char _binary___textos1_texto1_txt_start[];
extern char _binary___textos1_texto1_txt_end[];
extern char _binary___textos2_texto4_txt_start[];
extern char _binary___textos2_texto4_txt_end[];
int main(void) {
int i;
int sizeTexto1 = _binary___textos1_texto1_txt_end - _binary___textos1_texto1_txt_start;
int sizeTexto4 = _binary___textos2_texto4_txt_end - _binary___textos2_texto4_txt_start;
for (i=0;i<sizeTexto1;i++){
putchar(_binary___textos1_texto1_txt_start[i]);
}
for (i=0;i<sizeTexto4;i++){
putchar(_binary___textos2_texto4_txt_start[i]);
}
return EXIT_SUCCESS;
}
/*
============================================================================
名称:linkerTest.c
============================================================================
*/
#包括
#包括
外部字符二进制文本OS1文本1文本txt开始[];
外部字符二进制文本OS1文本1文本txt结束[];
外部字符二进制文本2文本4文本开始[];
外部字符二进制文本2文本4文本结束[];
内部主(空){
int i;
int sizeTexto1=_binary\uuuuuuu textos1\utexto1\utxt\u end-_binary\uuuuuuuuuu textos1\utexto1\utxt\u start;
int sizeTexto4=_binary\uuuuuuuuxtos2\u texto4\u txt\u end-_binary\uuuuuuuuuxtos2\u texto4\u txt\u start;
对于(i=0;i
rm libResources.a
rm names.txt
basedir=$1
for dir in "$basedir"/*; do
if test -d "$dir"; then
rm "$dir"/*.o
ld -r -b binary -o "$dir"/resources.o "$dir"/*
nm "$dir"/resources.o >> names.txt
fi
done
for dir in "$basedir"/*; do
if test -d "$dir"; then
ar q libResources.a "$dir"/*.o
fi
done
/*
============================================================================
Name : linkerTest.c
============================================================================
*/
#include <stdio.h>
#include <stdlib.h>
extern char _binary___textos1_texto1_txt_start[];
extern char _binary___textos1_texto1_txt_end[];
extern char _binary___textos2_texto4_txt_start[];
extern char _binary___textos2_texto4_txt_end[];
int main(void) {
int i;
int sizeTexto1 = _binary___textos1_texto1_txt_end - _binary___textos1_texto1_txt_start;
int sizeTexto4 = _binary___textos2_texto4_txt_end - _binary___textos2_texto4_txt_start;
for (i=0;i<sizeTexto1;i++){
putchar(_binary___textos1_texto1_txt_start[i]);
}
for (i=0;i<sizeTexto4;i++){
putchar(_binary___textos2_texto4_txt_start[i]);
}
return EXIT_SUCCESS;
}