天嵌 ARM开发社区

 找回密码
 注册
查看: 7325|回复: 5

求教:链接时Segmentation fault (core dumped)

[复制链接]
zyp568 发表于 2012-9-25 15:13:57 | 显示全部楼层 |阅读模式
本帖最后由 zyp568 于 2012-9-25 15:15 编辑

环境:ubuntu12.04 + arm-linux-gcc-4.3.3
自己写的裸机程序,想利用标准库构造一个Uart打印函数
  1. int UART_Printf( unsigned int iUARTID, const char *pFmt, ... )
复制代码
Makefile如下:
  1. objs1:= output/Head.o output/Init.o output/MMU.o output/Nand_K9F2G08U0B.o output/Interrupt.o output/InterruptEX.o output/ADC.o
  2. objs2:= output/Test.o output/TFTLCD.o output/Common.o output/UART.o
  3. objs := $(objs1) $(objs2)

  4. lib1 := /home/long/arm-linux-gcc-4.3.3/arm-none-linux-gnueabi/libc/armv4t/usr/lib/

  5. Test.bin : $(objs)
  6.         arm-linux-ld -TTest.lds -L$(lib1) -o output/Test.elf $^ -lc
  7.         arm-linux-objcopy -O binary -S output/Test.elf $@
  8.         arm-linux-objdump -D -m arm output/Test.elf > output/Test.dis
  9.         
  10. output/%.o : source/%.c
  11.         arm-linux-gcc -Wall -nostdlib -O2 -c -o $@ [        DISCUZ_CODE_20        ]lt;
  12.         
  13. output/%.o : source/%.s
  14.         arm-linux-gcc -Wall -nostdlib -O2 -c -o $@ [        DISCUZ_CODE_20        ]lt;
  15.         
  16. clean:
  17.         rm -f output/Test.elf output/Test.dis output/*.o Test.bin
复制代码
编译的时候出现错误:
  1. arm-linux-ld -TTest.lds -L/home/long/arm-linux-gcc-4.3.3/arm-none-linux-gnueabi/libc/armv4t/usr/lib/ -o output/Test.elf output/Head.o output/Init.o output/MMU.o output/Nand_K9F2G08U0B.o output/Interrupt.o output/InterruptEX.o output/ADC.o output/Test.o output/TFTLCD.o output/Common.o output/UART.o -lc
  2. arm-linux-ld: BFD (Sourcery G++ Lite 2009q1-203) 2.19.51.20090205 assertion fail /scratch/mitchell/builds/4.3-arm-none-linux-gnueabi-respin/lite/obj/binutils-src-2009q1-203-arm-none-linux-gnueabi-i686-pc-linux-gnu/bfd/elf32-arm.c:12507
  3. make: *** [Test.bin] Segmentation fault (core dumped)
复制代码


相关帖子

embedsky_lhh 发表于 2012-9-26 10:08:51 | 显示全部楼层
楼主的程序链接在哪个位置呢,有些LDS文件吗?
 楼主| zyp568 发表于 2012-10-5 20:30:55 | 显示全部楼层
embedsky_lhh 发表于 2012-9-26 10:08
楼主的程序链接在哪个位置呢,有些LDS文件吗?

链接文件如下,难道是代码分成了两个段造成的么?
只知道,不同段的代码不能相互调用~~,不知道C库会归到那个段去。
  1. SECTIONS {
  2.         first        0x00000000 : { output/Head.o output/Init.o output/Nand_K9F2G08U0B.o output/Interrupt.o output/InterruptEX.o }
  3.         second  0x30004000 : AT(4096) { output/Test.o output/Common.o }
  4. }
复制代码
embedsky_lhh 发表于 2012-10-8 11:25:15 | 显示全部楼层
zyp568 发表于 2012-10-5 20:30
链接文件如下,难道是代码分成了两个段造成的么?
只知道,不同段的代码不能相互调用~~,不知道C库会归到 ...

那入口地址没指定吧
 楼主| zyp568 发表于 2012-10-9 14:00:05 | 显示全部楼层
本帖最后由 zyp568 于 2012-10-9 17:10 编辑
embedsky_lhh 发表于 2012-10-8 11:25
那入口地址没指定吧

我的理解似乎有问题。
我的测试代码是裸奔的。
疑问:当代码里使用了C库的时候,那么运行时,应该要在有C库的环境运行吧?对于动态链接:
我试验过用 arm-linux-gcc 来编译+链接一个使用了vsprintf()的源文件hello.c,是没有问题的。
当我裸奔的时候,那么程序的入口点就是我自己指定的了,而不是arm-linux-gcc,
同时,裸奔的环境里没有C库。所以链接不能通过。即便通过了也运行不起来。

静态链接不知道行不行。
embedsky_lhh 发表于 2012-10-10 09:08:12 | 显示全部楼层
这只能静态链接吧,动态链接怎么能跑起来?看下uboot的相关makefile和lds应该可以搞出来,
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

i.MX8系列ARM cortex A53 M4 工控板上一条 /1 下一条

Archiver|手机版|小黑屋|天嵌 嵌入式开发社区 ( 粤ICP备11094220号-2 )

GMT+8, 2024-6-17 22:10 , Processed in 1.062500 second(s), 23 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表