MIT6.828 Lab5 make报错 解决方式

发布于:2022-12-04 ⋅ 阅读:(1028) ⋅ 点赞:(0)

昨天完成了lab4,今天开启了lab5。

Lab 5: File system, Spawn, and Shella​​​​​​

按照getting stared的流程走,当执行完git merge lab4后,想执行一下make指令看看是否这段ok,结果报错,如下所示:

lib/spawn.c:110:42: error: taking address of packed member of ‘struct Trapframe’ may result in an unaligned pointer value [-Werror=address-of-packed-member]
  110 |         if ((r = init_stack(child, argv, &child_tf.tf_esp)) < 0)
      |                                          ^~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make: *** [lib/Makefrag:37: obj/lib/spawn.o] Error 1

 我们可以注意到这行:

cc1: all warnings being treated as errors
报错原因就如该行英文的字面意思,因此想到去修改GNUmakefile中的Werror

打开lab5/下的GNUmakefile

#
# This makefile system follows the structuring conventions
# recommended by Peter Miller in his excellent paper:
#
#       Recursive Make Considered Harmful
#       http://aegis.sourceforge.net/auug97.pdf
#
OBJDIR := obj

# Run 'make V=1' to turn on verbose commands, or 'make V=0' to turn them off.
ifeq ($(V),1)
override V =
endif
ifeq ($(V),0)
override V = @
endif

-include conf/lab.mk

-include conf/env.mk

LABSETUP ?= ./

TOP = .

命令模式下输入

/Werror

可以在92行这里发现它:

 84 # Compiler flags
 85 # -fno-builtin is required to avoid refs to undefined functions in the kernel.
 86 # Only optimize to -O1 to discourage inlining, which complicates backtraces.
 87 CFLAGS := $(CFLAGS) $(DEFS) $(LABDEFS) -O1 -fno-builtin -I$(TOP) -MD
 88 CFLAGS += -fno-omit-frame-pointer
 89 CFLAGS += -std=gnu99
 90 CFLAGS += -static
 91 CFLAGS += -fno-pie
 92 CFLAGS += -Wall -Wno-format -Wno-unused -Werror -gstabs -m32
 93 # -fno-tree-ch prevented gcc from sometimes reordering read_ebp() before
 94 # mon_backtrace()'s function prologue on gcc version: (Debian 4.7.2-5) 4.7.2
 95 CFLAGS += -fno-tree-ch
 96
 97 # Add -fno-stack-protector if the option exists.
 98 CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-pr    otector)
92 CFLAGS += -Wall -Wno-format -Wno-unused -Werror -gstabs -m32

将-Werror删除,即变成以下内容:

92 CFLAGS += -Wall -Wno-format -Wno-unused -gstabs -m32

 保存后重新make,可见该处变成了warning

+ cc[USER] lib/spawn.c
lib/spawn.c: In function ‘spawn’:
lib/spawn.c:110:42: warning: taking address of packed member of ‘struct Trapframe’ may result in an unal         igned pointer value [-Waddress-of-packed-member]
  110 |         if ((r = init_stack(child, argv, &child_tf.tf_esp)) < 0)
      |                                          ^~~~~~~~~~~~~~~~
+ cc[USER] lib/pipe.c

当以为可以正常做实验的时候,发现竟然后续又来了一个报错:

+ cc[USER] fs/ide.c
+ cc[USER] fs/bc.c
+ cc[USER] fs/fs.c
+ cc[USER] fs/serv.c
+ cc[USER] fs/test.c
+ ld obj/fs/fs
ld: obj/fs/bc.o: in function `bc_pgfault':
fs/bc.c:31: multiple definition of `super'; obj/fs/ide.o:fs/ide.c:19: first defined here
ld: obj/fs/bc.o: in function `bc_pgfault':
fs/bc.c:31: multiple definition of `bitmap'; obj/fs/ide.o:fs/ide.c:19: first defined here
ld: obj/fs/fs.o: in function `walk_path':
fs/fs.c:233: multiple definition of `super'; obj/fs/ide.o:fs/ide.c:19: first defined here
ld: obj/fs/fs.o: in function `walk_path':
fs/fs.c:233: multiple definition of `bitmap'; obj/fs/ide.o:fs/ide.c:19: first defined here
ld: obj/fs/serv.o: in function `serve_read':
fs/serv.c:218: multiple definition of `bitmap'; obj/fs/ide.o:fs/ide.c:19: first defined here
ld: obj/fs/serv.o: in function `serve_read':
fs/serv.c:218: multiple definition of `super'; obj/fs/ide.o:fs/ide.c:19: first defined here
ld: obj/fs/test.o: in function `fs_test':
fs/test.c:10: multiple definition of `bitmap'; obj/fs/ide.o:fs/ide.c:19: first defined here
ld: obj/fs/test.o: in function `fs_test':
fs/test.c:10: multiple definition of `super'; obj/fs/ide.o:fs/ide.c:19: first defined here
make: *** [fs/Makefrag:52: obj/fs/fs] Error 1

 仔细一看,直接人傻了,fs不是在lab5才刚刚新增的吗?怎么上来就报multiple definition错误?????????

发现CSDN上似乎没有相关内容的解决方式。经过一段时间的研究后,发现应该这样修改:

打开fs/fs.c,如下所示

  1 #include <inc/string.h>
  2 #include <inc/partition.h>
  3
  4 #include "fs.h"
  5
  6 // --------------------------------------------------------------
  7 // Super block
  8 // --------------------------------------------------------------
  9
 10 // Validate the file system super-block.
 11 void
 12 check_super(void)
 13 {
 14         if (super->s_magic != FS_MAGIC)
 15                 panic("bad file system magic number");
 16
 17         if (super->s_nblocks > DISKSIZE/BLKSIZE)
 18                 panic("file system is too large");
 19
 20         cprintf("superblock is good\n");
 21 }

 在其中加上两行(下图的第6行和第7行):

  1 #include <inc/string.h>
  2 #include <inc/partition.h>
  3
  4 #include "fs.h"
  5
  6 struct Super *super;
  7 uint32_t *bitmap;
  8
  9 // --------------------------------------------------------------
 10 // Super block
 11 // --------------------------------------------------------------
 12
 13 // Validate the file system super-block.

再打开fs/fs.h,如下所示

  1 #include <inc/fs.h>
  2 #include <inc/lib.h>
  3
  4 #define SECTSIZE        512                     // bytes per disk sector
  5 #define BLKSECTS        (BLKSIZE / SECTSIZE)    // sectors per block
  6
  7 /* Disk block n, when in memory, is mapped into the file system
  8  * server's address space at DISKMAP + (n*BLKSIZE). */
  9 #define DISKMAP         0x10000000
 10
 11 /* Maximum disk size we can handle (3GB) */
 12 #define DISKSIZE        0xC0000000
 13
 14 struct Super *super;            // superblock
 15 uint32_t *bitmap;               // bitmap blocks mapped in memory
 16
 17 /* ide.c */
 18 bool    ide_probe_disk1(void);
 19 void    ide_set_disk(int diskno);
 20 void    ide_set_partition(uint32_t first_sect, uint32_t nsect);
 21 int     ide_read(uint32_t secno, void *dst, size_t nsecs);
 22 int     ide_write(uint32_t secno, const void *src, size_t nsecs);

将其中的14,15行前加上extern

 11 /* Maximum disk size we can handle (3GB) */
 12 #define DISKSIZE        0xC0000000
 13
 14 extern struct Super *super;             // superblock
 15 extern uint32_t *bitmap;                // bitmap blocks mapped in memory
 16

保存后返回,然后运行make,即可成功!

参考文献:Mark global variables as extern · fisop/jos@1cb1e47 · GitHub


网站公告

今日签到

点亮在社区的每一天
去签到