首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Makefile构建简单内核时出现“__aeabi_STH”错误

使用Makefile构建简单内核时出现“__aeabi_STH”错误
EN

Stack Overflow用户
提问于 2014-10-14 13:03:37
回答 1查看 275关注 0票数 0

现在,我正在尝试制作一个简单的内核,它只在启动后打印"Hello“。

我想用arm-linux-gnueabihf-gcc-4.8,

所以我像这样写Makefile

代码语言:javascript
复制
CC = arm-linux-gnueabihf-gcc-4.8
LD = arm-linux-gnueabihf-ld
OC = arm-linux-gnueabihf-objcopy

#CC = arm-none-eabi-gcc
#LD = arm-none-eabi-ld
#OC = arm-none-eabi-objcopy

CFLAGS  = -nostdinc -I. -I../include
CFLAGS += -Wall -Wstrict-prototypes -Wno-trigraphs -O2 
CFLAGS += -fno-strict-aliasing -fno-common -pipe #-mapcs-32
CFLAGS += -mcpu=xscale -msoft-float -fno-builtin #-mshort-load-bytes

LDFLAGS = -static -nostdlib -nostartfiles -nodefaultlibs -p -X -T ./main-ld-script

OCFLAGS = -O binary -R .note -R .comment -S

all: karlinux.c
    $(CC) -c $(CFLAGS) -o entry.o entry.S
    $(CC) -c $(CFLAGS) -o gpio.o gpio.c
    $(CC) -c $(CFLAGS) -o time.o time.c
    $(CC) -c $(CFLAGS) -o vsprintf.o vsprintf.c
    $(CC) -c $(CFLAGS) -o printf.o printf.c
    $(CC) -c $(CFLAGS) -o string.o string.c
    $(CC) -c $(CFLAGS) -o serial.o serial.c
    $(CC) -c $(CFLAGS) -o lib1funcs.o lib1funcs.S
    $(CC) -c $(CFLAGS) -o karlinux.o karlinux.c
    $(LD) $(LDFLAGS) -o karlinux_elf entry.o gpio.o time.o vsprintf.o printf.o string.o serial.o lib1funcs.o karlinux.o
    $(OC) $(OCFLAGS) karlinux_elf karlinux_img

clean:
    rm *.o
    rm karlinux_elf
    rm karlinux_img

但是,当LD做了一些事情时,我得到了一个错误。

错误信息是

代码语言:javascript
复制
xaliver@ubuntu:~/Documents/Karlinux/Karlinux/main$ make
arm-linux-gnueabihf-gcc-4.8 -c -nostdinc -I. -I../include -Wall -Wstrict-prototypes -Wno-trigraphs -O2 -fno-strict-aliasing -fno-common -pipe  -mcpu=xscale -msoft-float -fno-builtin  -o entry.o entry.S
arm-linux-gnueabihf-gcc-4.8 -c -nostdinc -I. -I../include -Wall -Wstrict-prototypes -Wno-trigraphs -O2 -fno-strict-aliasing -fno-common -pipe  -mcpu=xscale -msoft-float -fno-builtin  -o gpio.o gpio.c
arm-linux-gnueabihf-gcc-4.8 -c -nostdinc -I. -I../include -Wall -Wstrict-prototypes -Wno-trigraphs -O2 -fno-strict-aliasing -fno-common -pipe  -mcpu=xscale -msoft-float -fno-builtin  -o time.o time.c
arm-linux-gnueabihf-gcc-4.8 -c -nostdinc -I. -I../include -Wall -Wstrict-prototypes -Wno-trigraphs -O2 -fno-strict-aliasing -fno-common -pipe  -mcpu=xscale -msoft-float -fno-builtin  -o vsprintf.o vsprintf.c
arm-linux-gnueabihf-gcc-4.8 -c -nostdinc -I. -I../include -Wall -Wstrict-prototypes -Wno-trigraphs -O2 -fno-strict-aliasing -fno-common -pipe  -mcpu=xscale -msoft-float -fno-builtin  -o printf.o printf.c
arm-linux-gnueabihf-gcc-4.8 -c -nostdinc -I. -I../include -Wall -Wstrict-prototypes -Wno-trigraphs -O2 -fno-strict-aliasing -fno-common -pipe  -mcpu=xscale -msoft-float -fno-builtin  -o string.o string.c
arm-linux-gnueabihf-gcc-4.8 -c -nostdinc -I. -I../include -Wall -Wstrict-prototypes -Wno-trigraphs -O2 -fno-strict-aliasing -fno-common -pipe  -mcpu=xscale -msoft-float -fno-builtin  -o serial.o serial.c
serial.c:26:0: warning: "__REG" redefined [enabled by default]
 #define __REG(x) (x) 
 ^
In file included from serial.c:18:0:
../include/pxa255.h:46:0: note: this is the location of the previous definition
 #define __REG(x)   (*((volatile Word *) io_p2v (x))) 
 ^
arm-linux-gnueabihf-gcc-4.8 -c -nostdinc -I. -I../include -Wall -Wstrict-prototypes -Wno-trigraphs -O2 -fno-strict-aliasing -fno-common -pipe  -mcpu=xscale -msoft-float -fno-builtin  -o lib1funcs.o lib1funcs.S
arm-linux-gnueabihf-gcc-4.8 -c -nostdinc -I. -I../include -Wall -Wstrict-prototypes -Wno-trigraphs -O2 -fno-strict-aliasing -fno-common -pipe  -mcpu=xscale -msoft-float -fno-builtin  -o karlinux.o karlinux.c
arm-linux-gnueabihf-ld -static -nostdlib -nostartfiles -nodefaultlibs -p -X -T ./main-ld-script -o karlinux_elf entry.o gpio.o time.o vsprintf.o printf.o string.o serial.o lib1funcs.o karlinux.o
time.o: In function `SetWatchdog':
time.c:(.text+0x14): undefined reference to `__aeabi_idiv'
vsprintf.o: In function `number':
vsprintf.c:(.text+0x18e): undefined reference to `__aeabi_uidiv'
vsprintf.c:(.text+0x1a4): undefined reference to `__aeabi_uidivmod'
vsprintf.c:(.text+0x22a): undefined reference to `__stack_chk_fail'
vsprintf.c:(.text+0x230): undefined reference to `__stack_chk_guard'
printf.o: In function `printf':
printf.c:(.text+0x5e): undefined reference to `__stack_chk_fail'
printf.c:(.text+0x68): undefined reference to `__stack_chk_guard'
make: *** [all] Error 1

有人知道如何连接这些功能吗?

请帮帮我。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-02-22 16:01:04

我想你和我有同一本书。

ARM体系结构没有“划分”指令,所以当编译器(gcc交叉编译器)遇到“1/2”这样的除法指令时,再转换为“__aeabi_uidiv()”、“__aeabi_uidivmod()”等函数。

当链接器‘arm gnueabihf’进程链接时,链接器试图找到包含__aeabi_uidiv‘函数(和其他函数)的库。这个库是libgcc.a,但是您指定了选项'-nostdlib -nodefaultlib‘,所以链接器找不到__aeabi_uidiv()函数的主体。链接失败。

在我看来,作者的意图是这样的翻译函数__aeabi_uidiv()包含在lib1函数中。书中包含的工具链是gcc-3.3.2。gcc版本的arm交叉编译器将除法转换成'__udivsi3()‘函数,而不是'__aeabi_uidiv()’。‘lib1function s.s’中包含了'__udivsi3()‘函数实现。

总之,解决方案是两个。

  1. 使用gcc的工具链-3.3.2,而不是你的。(推荐)
  2. 将‘lib1function s.s’文件中的名称'__udivsi3()‘和’__udivsi3.()‘改为'__aeabi_uidiv()’‘__aeabi_uidiv.()’

我尝试了第二种方法并成功了,但是这个“未定义的引用.”问题再次出现在书的下一个例子,使我疯狂。要想在第二种方法中取得成功,我认为需要对编译和链接过程有更深入的理解。我推荐第一种方法。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26361552

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档