nanovms / nanos

A kernel designed to run one and only one application in a virtualized environment
https://nanos.org
Apache License 2.0
2.64k stars 137 forks source link

x86_64-elf-ld: error: linker script file 'linker_script' appears multiple times #1536

Open quantumsheep opened 3 years ago

quantumsheep commented 3 years ago

I'm having this error when building on macOS:

$ make run-noaccel                                            
[Some building logs...]
LD      /Users/qtmsheep/Development/nanos/output/platform/pc/boot/bin/stage2.elf
x86_64-elf-ld: error: linker script file 'linker_script' appears multiple times
make[2]: *** [/Users/qtmsheep/Development/nanos/output/platform/pc/boot/bin/stage2.elf] Error 1
make[1]: *** [boot] Error 2
make: *** [image] Error 2
quantumsheep commented 3 years ago

Running a dry-run using make run-noaccel -n, here's the concerned command:

echo "LD    /Users/qtmsheep/Development/nanos/output/platform/pc/boot/bin/stage2.elf"; x86_64-elf-ld -L/usr/local/opt/ncurses/lib -L/usr/local/opt/qt/lib -L/usr/local/opt/gstreamer/lib -L/usr/local/opt/gst-plugins-base/lib -L/usr/local/opt/freeglut/lib -L/usr/local/opt/openssl/lib --gc-sections -n --undefined=_start -T linker_script --gc-sections -n -T linker_script   /Users/qtmsheep/Development/nanos/output/platform/pc/boot/platform/pc/boot/stage2.o /Users/qtmsheep/Development/nanos/output/platform/pc/boot/platform/pc/boot/service32.o /Users/qtmsheep/Development/nanos/output/platform/pc/boot/src/drivers/ata.o /Users/qtmsheep/Development/nanos/output/platform/pc/boot/src/kernel/elf.o /Users/qtmsheep/Development/nanos/output/platform/pc/boot/src/kernel/kvm_platform.o /Users/qtmsheep/Development/nanos/output/platform/pc/boot/src/kernel/pagecache.o /Users/qtmsheep/Development/nanos/output/platform/pc/boot/src/runtime/buffer.o /Users/qtmsheep/Development/nanos/output/platform/pc/boot/src/runtime/extra_prints.o /Users/qtmsheep/Development/nanos/output/platform/pc/boot/src/runtime/format.o /Users/qtmsheep/Development/nanos/output/platform/pc/boot/src/runtime/memops.o /Users/qtmsheep/Development/nanos/output/platform/pc/boot/src/runtime/range.o /Users/qtmsheep/Development/nanos/output/platform/pc/boot/src/runtime/rbtree.o /Users/qtmsheep/Development/nanos/output/platform/pc/boot/src/runtime/runtime_init.o /Users/qtmsheep/Development/nanos/output/platform/pc/boot/src/runtime/pqueue.o /Users/qtmsheep/Development/nanos/output/platform/pc/boot/src/runtime/sg.o /Users/qtmsheep/Development/nanos/output/platform/pc/boot/src/runtime/symbol.o /Users/qtmsheep/Development/nanos/output/platform/pc/boot/src/runtime/table.o /Users/qtmsheep/Development/nanos/output/platform/pc/boot/src/runtime/timer.o /Users/qtmsheep/Development/nanos/output/platform/pc/boot/src/runtime/tuple.o /Users/qtmsheep/Development/nanos/output/platform/pc/boot/src/runtime/merge.o /Users/qtmsheep/Development/nanos/output/platform/pc/boot/src/runtime/string.o /Users/qtmsheep/Development/nanos/output/platform/pc/boot/src/x86_64/page.o /Users/qtmsheep/Development/nanos/output/platform/pc/boot/src/x86_64/serial.o /Users/qtmsheep/Development/nanos/output/platform/pc/boot/src/tfs/tfs.o /Users/qtmsheep/Development/nanos/output/platform/pc/boot/src/tfs/tlog.o   -o /Users/qtmsheep/Development/nanos/output/platform/pc/boot/bin/stage2.elf

As we can see we have two -T linker_script in the same command:

--undefined=_start -T linker_script --gc-sections -n -T linker_script
quantumsheep commented 3 years ago

I got it building by changing LDFLAGS+= to LDFLAGS= here: https://github.com/nanovms/nanos/blob/430a9fe3c97abed247ee50ccfecf3217eadf34b2/platform/pc/boot/Makefile#L39

It will need further reviewing as it doesn't seem like a great way of solving the issue 🙃

sanderssj commented 3 years ago

What's your version of OS X? I haven't seen this on 10.14.

quantumsheep commented 3 years ago

@sanderssj Big Sur 11.4

sanderssj commented 3 years ago

I tried to build on a Big Sur machine and still can't duplicate. Can you give me the output of these commands?

pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
pkgutil --pkg-info=com.apple.pkg.CLTools_SDK_macOS110
xcode-select -p
which make
make --version
quantumsheep commented 3 years ago

pkgutil --pkg-info=com.apple.pkg.CLTools_Executables

No receipt for 'com.apple.pkg.CLTools_Executables' found at '/'.

pkgutil --pkg-info=com.apple.pkg.CLTools_SDK_macOS110

No receipt for 'com.apple.pkg.CLTools_SDK_macOS110' found at '/'.

xcode-select -p

/Applications/Xcode.app/Contents/Developer

which make

/usr/bin/make

make --version

GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for i386-apple-darwin11.3.0
sanderssj commented 3 years ago

Thanks for the information. I'm still not able to duplicate the problem, and I'm not sure where a second expansion would be happening. Would you mind trying to install the xcode command line tools and switching to those and trying to build a freshly cloned repo?

xcode-select --install
sudo xcode-select -s /Library/Developer/CommandLineTools