llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
26.83k stars 11.01k forks source link

AVR rtlib linking quirks warning emitted even when not linking #96743

Open DavidSpickett opened 1 week ago

DavidSpickett commented 1 week ago

Originally reported in https://discourse.llvm.org/t/how-to-debug-to-learn-llvm-backend/79655/8.

$ cat /tmp/test.c
int main() {
  return 0;
}

If I try to link the program I get these warnings:

$ ./bin/clang --target=avr /tmp/test.c -o /dev/null
clang: warning: no target microcontroller specified on command line, cannot link standard libraries, please pass -mmcu=<mcu name> [-Wavr-rtlib-linking-quirks]
clang: warning: standard library not linked and so no interrupt vector table or compiler runtime routines will be linked [-Wavr-rtlib-linking-quirks]
clang: warning: support for passing the data section address to the linker for microcontroller '' is not implemented [-Wavr-rtlib-linking-quirks]
clang: error: unable to execute command: Executable "avr-ld" doesn't exist!
clang: error: avr-ld command failed with exit code 1 (use -v to see invocation)

Which is expected. What is not expected is that I get one of them even when not linking:

$ ./bin/clang --target=avr /tmp/test.c -S -o -
clang: warning: no target microcontroller specified on command line, cannot link standard libraries, please pass -mmcu=<mcu name> [-Wavr-rtlib-linking-quirks]
        .text
<...>

Also emitted for -E:

$ ./bin/clang --target=avr /tmp/test.c -E -o -
clang: warning: no target microcontroller specified on command line, cannot link standard libraries, please pass -mmcu=<mcu name> [-Wavr-rtlib-linking-quirks]
# 1 "/tmp/test.c"

And -c:

$ ./bin/clang --target=avr /tmp/test.c -c -o /dev/null
clang: warning: no target microcontroller specified on command line, cannot link standard libraries, please pass -mmcu=<mcu name> [-Wavr-rtlib-linking-quirks]

And presumably any other modes that do not link.

Maybe there is some other side effect of -mmcu=... that would effect assembly or the preprocessor (seems most likely), but if so, perhaps the warning could mention that too?

llvmbot commented 1 week ago

@llvm/issue-subscribers-clang-driver

Author: David Spickett (DavidSpickett)

Originally reported in https://discourse.llvm.org/t/how-to-debug-to-learn-llvm-backend/79655/8. ``` $ cat /tmp/test.c int main() { return 0; } ``` If I try to link the program I get these warnings: ``` $ ./bin/clang --target=avr /tmp/test.c -o /dev/null clang: warning: no target microcontroller specified on command line, cannot link standard libraries, please pass -mmcu=<mcu name> [-Wavr-rtlib-linking-quirks] clang: warning: standard library not linked and so no interrupt vector table or compiler runtime routines will be linked [-Wavr-rtlib-linking-quirks] clang: warning: support for passing the data section address to the linker for microcontroller '' is not implemented [-Wavr-rtlib-linking-quirks] clang: error: unable to execute command: Executable "avr-ld" doesn't exist! clang: error: avr-ld command failed with exit code 1 (use -v to see invocation) ``` Which is expected. What is not expected is that I get one of them even when not linking: ``` $ ./bin/clang --target=avr /tmp/test.c -S -o - clang: warning: no target microcontroller specified on command line, cannot link standard libraries, please pass -mmcu=<mcu name> [-Wavr-rtlib-linking-quirks] .text <...> ``` Also emitted for `-E`: ``` $ ./bin/clang --target=avr /tmp/test.c -E -o - clang: warning: no target microcontroller specified on command line, cannot link standard libraries, please pass -mmcu=<mcu name> [-Wavr-rtlib-linking-quirks] # 1 "/tmp/test.c" ``` And `-c`: ``` $ ./bin/clang --target=avr /tmp/test.c -c -o /dev/null clang: warning: no target microcontroller specified on command line, cannot link standard libraries, please pass -mmcu=<mcu name> [-Wavr-rtlib-linking-quirks] ``` And presumably any other modes that do not link. Maybe there is some other side effect of `-mmcu=...` that would effect assembly or the preprocessor (seems most likely), but if so, perhaps the warning could mention that too?
benshi001 commented 1 week ago

The -mmcu option does affect even with -c/-S, some instructions are not available on compact devices, such as JMP/CALL (4-byte instructions), and clang/llvm will decide to emit them or not according to -mmcu.

But it is to verbose to mention that, so how about change the warning more brief?

clang: warning: no target microcontroller specified, please pass -mmcu=<mcu name> [-Wavr-rtlib-linking-quirks]
DavidSpickett commented 1 week ago

That works, and if you try to link you'll get this warning as well:

warning: standard library not linked and so no interrupt vector table or compiler runtime routines will be linked

So it's implied that -mmcu is doing more than just selecting libraries.

DavidSpickett commented 1 week ago

Also, while I have your attention, when I selected avr1 I got a crash: https://godbolt.org/z/GeGqWxMrz

Is this worth reporting or is the support here known to have issues? GCC has assembler only support, so maybe I am just asking clang to do something silly here.

benshi001 commented 1 week ago

Also, while I have your attention, when I selected avr1 I got a crash: https://godbolt.org/z/GeGqWxMrz

Is this worth reporting or is the support here known to have issues? GCC has assembler only support, so maybe I am just asking clang to do something silly here.

Please submit another issue for this crash. Thanks!