gpt4 book ai didi

c - 裸机 (elf) 程序构建的 dlmalloc 编译期间出错

转载 作者:行者123 更新时间:2023-11-30 19:34:05 29 4
gpt4 key购买 nike

我正在使用 gnu sparc 工具链。我有 sparc-ab-elf-gcc 和 sparc-ab-linux-gcc。 (“ab”是处理器名称)。我想在裸机(没有操作系统)上编译一个使用 malloc 和 free 的程序(该程序应该在 Linux 上运行)。所以我应该使用 sparc-ab-elf-gcc 编译它。我听说我可以在这种情况下使用 dlmalloc 。 (参见 stdlib-like library on bare metal environment? (memory management and hopefully pthread support) )但我看到一些简单测试程序的编译错误,该程序每次只执行一次 malloc 和 free 。

// test malloc, realloc and free
#include <aldebaran.h>
#include <malloc.h>


int main()
{
int i;

ab_printf("%s\n",CKIM_XX);
char *buff = dlmalloc(100);
for(i = 0; i < 100; i++) {
buff[i] = (char) i;
}
ab_printf("buff = %x\n'");
for(i=0; i<100; i++) {
ab_printf("%d ", buff[i]);
}
ab_printf("\n");
dlfree(buff);
return 0;
}


ckim@stph45:~/prj2/abts/yolo-bare/darknet] make test3
sparc-ab-elf-gcc -c -I./src -I../include -I/opt/abde/sparc-ab-elf/include -DALDEBARAN_FPGA -DABC_CT -O3 -ffast-math -fcommon -msoft-float -mcpu=v8 -Wa,-xarch=v8plusb -Wall -Wfatal-errors ./src/malloc.c -o obj/malloc.o
./src/malloc.c:571:40: fatal error: sys/mman.h: No such file or directory
compilation terminated.
make: *** [obj/malloc.o] Error 1

我的裸机系统没有sys/mman.h(我在elf工具链库上搜索到它),所以在定义LACKS_SYS_MMAN_H后再次尝试并得到

ckim@stph45:~/prj2/abts/yolo-bare/darknet] make test3
sparc-ab-elf-gcc -c -I./src -I../include -I/opt/abde/sparc-ab-elf/include -DALDEBARAN_FPGA -DABC_CT -O3 -ffast-math -fcommon -msoft-float -mcpu=v8 -Wa,-xarch=v8plusb -Wall -Wfatal-errors -DLACKS_SYS_MMAN_H ./src/test3.c -o obj/test3.o
sparc-ab-elf-gcc -c -I./src -I../include -I/opt/abde/sparc-ab-elf/include -DALDEBARAN_FPGA -DABC_CT -O3 -ffast-math -fcommon -msoft-float -mcpu=v8 -Wa,-xarch=v8plusb -Wall -Wfatal-errors -DLACKS_SYS_MMAN_H ./src/malloc.c -o obj/malloc.o
./src/malloc.c: In function 'mmap_alloc':
./src/malloc.c:2924:5: warning: implicit declaration of function 'mmap' [-Wimplicit-function-declaration]
./src/malloc.c:2924:24: error: 'PROT_READ' undeclared (first use in this function)
compilation terminated due to -Wfatal-errors.
make: *** [obj/malloc.o] Error 1

dlmalloc.c 是一个非常长的程序。 (我把它分为malloc.h和malloc.c)下面是出错的函数..

/* Malloc using mmap */
static void* mmap_alloc(mstate m, size_t nb) {
size_t mmsize = mmap_align(nb + SIX_SIZE_T_SIZES + CHUNK_ALIGN_MASK);
if (m->footprint_limit != 0) {
size_t fp = m->footprint + mmsize;
if (fp <= m->footprint || fp > m->footprint_limit)
return 0;
}
if (mmsize > nb) { /* Check for wrap around 0 */
char* mm = (char*)(CALL_DIRECT_MMAP(mmsize)); <=== line causing error.
if (mm != CMFAIL) {
size_t offset = align_offset(chunk2mem(mm));
size_t psize = mmsize - offset - MMAP_FOOT_PAD;
mchunkptr p = (mchunkptr)(mm + offset);
p->prev_foot = offset;
p->head = psize;
mark_inuse_foot(m, p, psize);
chunk_plus_offset(p, psize)->head = FENCEPOST_HEAD;
chunk_plus_offset(p, psize+SIZE_T_SIZE)->head = 0;

if (m->least_addr == 0 || mm < m->least_addr)
m->least_addr = mm;
if ((m->footprint += mmsize) > m->max_footprint)
m->max_footprint = m->footprint;
assert(is_aligned(chunk2mem(p)));
check_mmapped_chunk(m, p);
return chunk2mem(p);
}
}
return 0;
}

有人可以给我一盏灯吗?

最佳答案

I heard I can use dlmalloc for this case

再次阅读该答案。特别注意:“......你应该能够适应......”。您还没有完成改编部分。

关于c - 裸机 (elf) 程序构建的 dlmalloc 编译期间出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44388743/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com