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

How to link stm8.lib? #2

Closed
jxltom opened this issue Sep 29, 2020 · 9 comments
Closed

How to link stm8.lib? #2

jxltom opened this issue Sep 29, 2020 · 9 comments

Comments

@jxltom
Copy link

jxltom commented Sep 29, 2020

Following error is raised when linking with stm8-ld. It looks like stm8.lib is not linked. I tried with -L and -l options, but stm-ld reports can not find library.

main.c:201: undefined reference to `___uint2fs'
main.c:206: undefined reference to `___fslt'
main.c:206: undefined reference to `___fslt'
main.c:217: undefined reference to `_(float, short, short, bool __restrict)'
main.c:217: undefined reference to `_(float, short, double, int, void)'
main.c:217: undefined reference to `___fsmul'
main.c:217: undefined reference to `___fs2uint'
main.c:221: undefined reference to `_(float, short, short, bool __restrict)'
main.c:221: undefined reference to `_(float, short, double, int, void)'
main.c:221: undefined reference to `___fsmul'
main.c:221: undefined reference to `___fs2uint'
@XaviDCR92
Copy link
Owner

This issue arises when you do arithmetic operations such as divisions or multiplications, as they rely on functions provided by the compiler. SDCC includes both platform-specific and portable implementations so sdld includes them on the link phase.
As a quick workaround, you can compile any needed source files corresponding to the portable implementations e.g.: _fsmul.c using the same compilation flags as stm8-dce-example and add them into the objects list for stm8-ld. While the platform-specific implementations are surely more optimized, they are written in assembly using sdas syntax instead of stm8-as, so you will need some (minor) modifications to make them work on stm8-as.
Therefore, should the sdcc-gas repository be ever merged into upstream, two versions of the assembly code should be then provided: one for sdas and one for stm8-as.

@jxltom
Copy link
Author

jxltom commented Sep 30, 2020

Hey @XaviDCR92 many thanks for the clarification!

I've compiled and linked _fs2uinit.c, _fs2ulong.c, _fslt.c, _fsmul.c, _uint2fs.c, _ulong2fs.c and __mulsint2slong.s (with a little bit modification) to remove most of the errors.

However, following errors still exist. Do you mind telling me which files should I add? Thanks!

.pio/build/default/src/main.o: In function `_ADC_REG':
main:(.text._ADC_REG+0xa0): undefined reference to `_(float, short, short, bool __restrict)'
main:(.text._ADC_REG+0xb0): undefined reference to `_(float, short, double, int, void)'
main:(.text._ADC_REG+0xe6): undefined reference to `_(float, short, short, bool __restrict)'
main:(.text._ADC_REG+0xf6): undefined reference to `_(float, short, double, int, void)

@XaviDCR92
Copy link
Owner

I am not sure what your ADC_REG function is doing to require such symbols. Moreover, I see their names have a parameter list in them for some reason, but can't tell you why, I'm sorry.
Could you please paste either ADC_REG or the problematic lines so we can find the root cause of the issue? Thanks a lot.

@jxltom
Copy link
Author

jxltom commented Oct 1, 2020

Thanks for help!

After some digging, I can reproduce the issue with below code. It looks like it is happending when doing arithmetic with float and int and then passing it to a function.

.pio/build/default/src/main.o: In function `_main':
main:(.text._main+0x13): undefined reference to `_(float, short, short, bool __restrict)'
#include "stm8s_adc1.h"

void test_function(uint16_t value) {}

void main(void)
{
  uint16_t value = 1.0f - ADC1_GetConversionValue();
  test_function(value);
}

@XaviDCR92
Copy link
Owner

The error message is, for some reason, very unfortunate. Please add the following files to the build:

_fsadd.c
_fsdiv.c
_fsmul.c
_fssub.c

Adding them worked for me.

@jxltom
Copy link
Author

jxltom commented Oct 1, 2020

Thanks! It finally working!

It will be nice, If there is a precompiled version of stm8.lib provided for sdcc-gas 😄

@XaviDCR92
Copy link
Owner

If I'm not mistaken, the stm8-binutils-gdb should be modified to include stm8.lib, similarly to how libc.a is included. I should take a look at how to do that.

@jxltom
Copy link
Author

jxltom commented Oct 8, 2020

That will be great! It will be much easier for the linking.

@jxltom
Copy link
Author

jxltom commented Oct 8, 2020

Thanks for the help! I will close this issue since it is actually solved.

I created another issue XaviDCR92/stm8-binutils-gdb#1 to tracking the precompiled stm8.lib feature.

@jxltom jxltom closed this as completed Oct 8, 2020
MarrekNozka added a commit to MarrekNozka/stm8-dce-example that referenced this issue Mar 16, 2021
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

2 participants