Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined reference to `__divmoddi4' #6

Open
tclin914 opened this issue May 28, 2019 · 2 comments
Open

undefined reference to `__divmoddi4' #6

tclin914 opened this issue May 28, 2019 · 2 comments

Comments

@tclin914
Copy link

Hi,

I got a problem when I run avr-lit --llvm-sysroot /work/llvm-build.

"/usr/bin/avr-ld" /tmp/statistics-04f55b.o -o /tmp/.tmp5oeKTE --gc-sections -L/usr/lib/avr/lib/avr5 -L/usr/lib/avr/lib/avr5 -L/usr/lib/gcc/avr/4.9.2/avr5 -l:crtatmega328p.o -lgcc -lm -lc -latmega328p -mavr5
/tmp/statistics-04f55b.o: In function `LBB67_7':
statistics.cpp:(.progmem.data+0x276a):` undefined reference to `__divmoddi4'

It seems that libgcc doesn't have the function __divmoddi4. But LLVM will lower i64 sdivrem to libcall __divmoddi4. Are you use libgcc or compiler-rt?

Thank you.

@dylanmckay
Copy link
Owner

I am using libgcc, which as far as I remember, does have the __divmoddi4 symbol.

AVR-GCC/avr-libc has special cases to the calling convention for certain arithmetic routines that require special lowering to match the custom calling convention.

See https://gcc.gnu.org/wiki/avr-gcc heading "Exceptions to the Calling Convention".

The AVR LLVM backend will always emit these special calls to __divmod..., making it incompatible with compiler-rt. This affects runtime library calls to some division and multiplication routines.

Ideally, compiler-rt proper would be extended to support AVR, and then the AVR backend could be taught to ignore the ABI special cases when compiler-rt is linked. It's been a while since I last looked at it, but I seem to recall compiler-rt missing some AVR libgcc routines that are used by avr-gcc and correspondingly, AVR-LLVM. I'm pretty sure the __divmod* family of functions for small integer types were the problem, as compiler-rt didn't seem to cater for esoteric targets like AVR that have limited or a complete lack of multiplication/division hardware support.

@aykevl
Copy link

aykevl commented Jun 16, 2020

I believe this is a bug in LLVM that is fixed in the master branch: https://reviews.llvm.org/D78437

Are you using LLVM 10 or the nightly build (LLVM 11)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants