The first successful build of OpenBSD base system

Although the document of building OpenBSD base system is very simple, it still costs me nearly half a week to complete this work. I shared the experience here and hope the lessons I learned can help more newbies like me:

(1) The most important thing is about /usr/obj folder: it must be clean; belongs to wobj and mode is 770. I confronted the annoyed and weird “Permission denied” issue and have recorded the incident in this post before.

(2) I used to think once /usr/obj is calibrated, the compilation will go smoothly. Unfortunately, a more bizarre linking issue harassed me again:

cc -O2 -pipe  -DPIE_DEFAULT=1         -o gdb gdb.o libgdb.a ../bfd/libbfd.a -lreadline ../opcodes/libopcodes.a  -liberty -lncurses -lm     -liberty  -lkvm
libgdb.a(main.o): In function `captured_main':
/usr/src/gnu/usr.bin/binutils/gdb/main.c:(.text+0x7e6): warning:
warning: strcpy() is almost always misused, please use strlcpy()
/usr/src/gnu/usr.bin/binutils/gdb/main.c:(.text+0x7ff): warning:
warning: strcat() is almost always misused, please use strlcat()
libgdb.a(target.o): In function `normal_pid_to_str':
/usr/src/gnu/usr.bin/binutils/gdb/target.c:(.text+0x3047): warning:
warning: sprintf() is often misused, please use snprintf()
libgdb.a(main.o): In function `captured_main':
/usr/src/gnu/usr.bin/binutils/gdb/main.c:(.text+0xa4): undefined reference to `bindtextdomain'
/usr/src/gnu/usr.bin/binutils/gdb/main.c:(.text+0xac): undefined reference to `textdomain'
/usr/src/gnu/usr.bin/binutils/gdb/main.c:(.text+0x4b7): undefined reference to `dcgettext'
/usr/src/gnu/usr.bin/binutils/gdb/main.c:(.text+0x606): undefined reference to `dcgettext'
/usr/src/gnu/usr.bin/binutils/gdb/main.c:(.text+0x78d): undefined reference to `dcgettext'
/usr/src/gnu/usr.bin/binutils/gdb/main.c:(.text+0x9b9): undefined reference to `dcgettext'
/usr/src/gnu/usr.bin/binutils/gdb/main.c:(.text+0xa60): undefined reference to `dcgettext'
libgdb.a(main.o):/usr/src/gnu/usr.bin/binutils/gdb/main.c:(.text+0xb46): more undefined references to `dcgettext' follow
cc: error: linker command failed with exit code 1 (use -v to see invocation)
*** Error 1 in gnu/usr.bin/binutils/obj/gdb (Makefile:1176 'gdb')
*** Error 1 in gnu/usr.bin/binutils/obj (Makefile:21479 'all-gdb')
*** Error 1 in gnu/usr.bin/binutils (Makefile.bsd-wrapper:46 'all')
*** Error 1 in gnu/usr.bin (<bsd.subdir.mk>:48 'all')
*** Error 1 in gnu (<bsd.subdir.mk>:48 'all')
*** Error 1 in . (<bsd.subdir.mk>:48 'all')
*** Error 1 in . (Makefile:95 'do-build')
*** Error 1 in /usr/src (Makefile:74 'build')

I totally get lost in this blocking issue. After sending helps in both mailing list and Facebook, though many veterans gave good comments, after all they can’t approach my server, I still need to fix this issue myself at the end.

I began to doubt the upgrade of v6.2 because this is also the first time I upgrade OpenBSD. Although I couldn’t explain why the upgrade can be related to this link error, I don’t have other methods So I tried to follow the manual to do upgrade again. Now that I had done the OS upgrade, I also tried to refresh -current source code:

# cvs -q up -Pd
? mcount.d
? mcount.po
? gnu/usr.bin/binutils/gdb/.gdbinit
? gnu/usr.bin/binutils/gdb/Makefile
? gnu/usr.bin/binutils/gdb/config.cache
? gnu/usr.bin/binutils/gdb/config.h
? gnu/usr.bin/binutils/gdb/config.log
? gnu/usr.bin/binutils/gdb/config.status
? gnu/usr.bin/binutils/gdb/stamp-h
? gnu/usr.bin/binutils/gdb/doc/Makefile
? gnu/usr.bin/binutils/gdb/doc/config.log
? gnu/usr.bin/binutils/gdb/doc/config.status
? gnu/usr.bin/binutils/gdb/testsuite/Makefile
? gnu/usr.bin/binutils/gdb/testsuite/config.log
? gnu/usr.bin/binutils/gdb/testsuite/config.status
? gnu/usr.bin/binutils/gdb/testsuite/gdb.ada/Makefile
? gnu/usr.bin/binutils/gdb/testsuite/gdb.ada/gnat_ada.gpr
? gnu/usr.bin/binutils/gdb/testsuite/gdb.arch/Makefile
? gnu/usr.bin/binutils/gdb/testsuite/gdb.asm/Makefile
? gnu/usr.bin/binutils/gdb/testsuite/gdb.base/Makefile
? gnu/usr.bin/binutils/gdb/testsuite/gdb.cp/Makefile
? gnu/usr.bin/binutils/gdb/testsuite/gdb.disasm/Makefile
? gnu/usr.bin/binutils/gdb/testsuite/gdb.dwarf2/Makefile
? gnu/usr.bin/binutils/gdb/testsuite/gdb.fortran/Makefile
? gnu/usr.bin/binutils/gdb/testsuite/gdb.java/Makefile
? gnu/usr.bin/binutils/gdb/testsuite/gdb.mi/Makefile
? gnu/usr.bin/binutils/gdb/testsuite/gdb.objc/Makefile
? gnu/usr.bin/binutils/gdb/testsuite/gdb.stabs/Makefile
? gnu/usr.bin/binutils/gdb/testsuite/gdb.stabs/config.log
? gnu/usr.bin/binutils/gdb/testsuite/gdb.stabs/config.status
? gnu/usr.bin/binutils/gdb/testsuite/gdb.threads/Makefile
? gnu/usr.bin/binutils/gdb/testsuite/gdb.trace/Makefile
...... 

Man! Why there are files began with ?? I see, I did some experiments in /usr/src directory before, and I didn’t notice that the source code had been polluted. That may be the root cause! As expected, after cleaning up the /usr/src, the build succeed finally!

It is time to wrap up, and the takeaways of building OpenBSD base system are as following:
(1) Clean up the /usr/obj and check its attributes carefully!
(2) Keep /usr/src synchronized with upstream and make sure it’s not messed up!

Leave a Reply

Your email address will not be published. Required fields are marked *