LD:如何将.a文件与.o文件添加到指定sections

本文介绍了一个具体的ARM系统内存布局配置示例,详细展示了如何通过链接脚本定义不同内存区域,并指定了特定文件如main.c、clock.c及libgcc.a中代码段的位置。此配置对于理解嵌入式系统启动过程中的内存分配至关重要。

 核心代码与注释如下:

MEMORY
{
    ...
    ARM_SECT0 (rx) : ORIGIN = 0x60aa8000, LENGTH = 0x58000 
    ARM_SECT1 (rx) : ORIGIN = 0x20800000, LENGTH = 0x180000 /* 1.5M */
    ...
}

ENTRY(Reset_Handler)

SECTIONS
{
    ...
    .text :
	{
		. = ALIGN(4);
		_stext = .;
        
        /* 将main.c和clock.c文件编译出来的text指定到ARM_SECT0 */
		*main.o(.text*)
		*clock.o(.text*)

        /* 将libgcc.a的text指定到ARM_SECT0 */
		*\libgcc.a:*

		_etext = .;
	} > ARM_SECT0

	.text_xip : 
	{
		. = ALIGN(4);
		_stext = .;
        
        /* 将main.c和clock.c文件编译出来的text从ARM_SECT1移除 */
		*(EXCLUDE_FILE(*main.o
					   *clock.o) 
		  .text*)

		/* .ctors */
		*crtbegin.o(.ctors)
		*crtbegin?.o(.ctors)
		*(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
		*(SORT(.ctors.*))
		*(.ctors)

		/* .dtors */
 		*crtbegin.o(.dtors)
 		*crtbegin?.o(.dtors)
 		*(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
 		*(SORT(.dtors.*))
 		*(.dtors)

		. = ALIGN(4);
	} > ARM_SECT1
    ...
}

编译结果

#include "../lib/util/setid.h" 我在util_sec 中有这个头文件 这个头文件里面就有那些函数 而且在头文件的目录下面还有他的.c 文件 为什么还会出现这个问题 ['arm-buildroot-linux-gnueabi-gcc', 'test.c.1.o', '-o/data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/samba-4.14.5/bin/.conf_check_4e05bc9a1fb40278b17755b9753a363f/testbuild/default/testprog', '-Wl,-Bstatic', '-Wl,-Bdynamic', '-L/usr/local/lib', '-L/usr/local/lib', '-L/data/red-round3/red-round3/Iplatform/openwrt/staging_dir/target-arm-openwrt-linux-uclibc-be220v1/usr/lib', '-L/data/red-round3/red-round3/Iplatform/openwrt/staging_dir/target-arm-openwrt-linux-uclibc-be220v1/lib', '-Wl,-rpath-link,/data/red-round3/red-round3/Iplatform/openwrt/staging_dir/target-arm-openwrt-linux-uclibc-be220v1/usr/lib', '-L/data/red-round3/red-round3/Iplatform/openwrt/../../bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/usr/lib', '-L/data/red-round3/red-round3/Iplatform/openwrt/../../bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/lib', '-Wl,--gc-sections,--as-needed', '-lgnutls', '-Wl,-no-undefined', '-Wl,--export-dynamic'] err: arm-buildroot-linux-gnueabi-gcc: WARNING: unsafe header/library path used in cross-compilation: '-L/usr/local/lib' arm-buildroot-linux-gnueabi-gcc: WARNING: unsafe header/library path used in cross-compilation: '-L/usr/local/lib' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: warning: library search path "/usr/local/lib" is unsafe for cross-compilation /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: warning: library search path "/usr/local/lib" is unsafe for cross-compilation /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: test.c.1.o: in function `gain_root_privilege': test.c:(.text.gain_root_privilege+0xc): undefined reference to `setuidx' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: test.c:(.text.gain_root_privilege+0x18): undefined reference to `setuidx' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: test.c.1.o: in function `gain_root_group_privilege': test.c:(.text.gain_root_group_privilege+0xc): undefined reference to `setgidx' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: test.c:(.text.gain_root_group_privilege+0x18): undefined reference to `setgidx' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: test.c.1.o: in function `set_effective_uid': test.c:(.text.set_effective_uid+0x10): undefined reference to `setuidx' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: test.c.1.o: in function `set_effective_gid': test.c:(.text.set_effective_gid+0x10): undefined reference to `setgidx' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: test.c.1.o: in function `restore_re_uid_fromroot': test.c:(.text.restore_re_uid_fromroot+0x1c): undefined reference to `setuidx' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: test.c:(.text.restore_re_uid_fromroot+0x28): undefined reference to `setuidx' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: test.c.1.o: in function `restore_re_gid': test.c:(.text.restore_re_gid+0x1c): undefined reference to `setgidx' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: test.c:(.text.restore_re_gid+0x28): undefined reference to `setgidx' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: test.c.1.o: in function `become_user_permanently': test.c:(.text.become_user_permanently+0x1c): undefined reference to `setgidx' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: test.c:(.text.become_user_permanently+0x28): undefined reference to `setgidx' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: test.c:(.text.become_user_permanently+0x3c): undefined reference to `setuidx' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: test.c:(.text.become_user_permanently+0x48): undefined reference to `setuidx' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: test.c.1.o: in function `main': test.c:(.text.startup.main+0x48): undefined reference to `setuidx' collect2: error: ld returned 1 exit status from /data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/samba-4.14.5/source3: Test does not build: Traceback (most recent call last): File "/data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/samba-4.14.5/third_party/waf/waflib/Configure.py", line 602, in run_build bld.compile() File "/data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/samba-4.14.5/third_party/waf/waflib/Build.py", line 355, in compile raise Errors.BuildError(self.producer.error) waflib.Errors.BuildError: Build failed -> task in 'testprog' failed with exit status 1 (run with -v to display more information) from /data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/samba-4.14.5/source3: The configuration failed not found
最新发布
11-05
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值