Open dylanmckay opened 9 years ago
MBA-Anton:bin asmirnov$ ./clang -v
clang version 3.8.0 (https://github.com/avr-llvm/clang.git 3b2c949e21022c841c80fca5e79d1f1387cd012c) (llvm/llvm.git 47a798c880f7baaf6b80b99e8653a22a28efc025)
Target: x86_64-apple-darwin14.3.0
Thread model: posix
Here is HardwareSerial.cpp
and HardwareSerial.ll
(just to check if weak
is absent in ll):
https://gist.github.com/4ntoine/f00d0651bdda6744e41e.
I've used
MBA-Anton:bin asmirnov$ ./clang -c -g -Os -Wall -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -I/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino -I/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/avr/variants/standard -I/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/avr/include --target=avr /Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/HardwareSerial.cpp -o /tmp/arduino_test1/HardwareSerial.cpp.o
to get .ll from .cpp (just like original Arduino IDE does, except i've replaced -o /tmp/arduino_test1/HardwareSerial.cpp.o
with -S -emit-llvm -o /tmp/arduino_test1/HardwareSerial.ll
).
I'm able to find weak
in .ll:
define weak void @_Z14serialEventRunv() #0 {
also i can see some 'extern_weak' attributes:
; Function Attrs: optsize
declare extern_weak void @_Z11serialEventv() #0
This means that this is not a clang problem, but an LLVM problem.
LLVM does support weak linkage here. Function signatures can also be annotated with weak
and so LLVM does support it.
The problem must be deeper.
as you can see in SO question, i've tried Apple's LLVM/Clang and non-avr sources and it can't link. I believe it's a bug, but i've asked the question to both cfe-users@ and cfe-dev@ maillists.
Note: Migrated from here.
Weakly defined symbols like so (taken from Arduino):
Are failing during the link stage due to undefined references to the weak symbols (by GNU's
avr-ld
). Weak symbols have the property that if they are not defined, they are set to null instead. It makes no sense for a weak undefined symbol, thus this error must lay withclang
orllvm
not placing theweak
attribute in the ELF object file.