I have been working with STM8 for a long time in SI, so I decided to try to go with IAR on Vscode + Platformio (SDCC + SPL + GDB), because from my point of view, at least simple and convenient.
But I ran into one unpleasant feature - when using libraries, SDCC generates an incorrect .elf file.
The analysis led me to a ticket [#3200] that describes the same behavior that I encountered.
But my analysis showed that this has to do with the Windows-paths of the source files, and not the number of these files in the project nor their accompanying warnings.
For this reason, I opened a new ticket.
The main problem is that file paths are formatted. Perhaps for Linux (I'm not an expert) - this is a normal situation when \n, \a, \b etc are replaced with the corresponding symbol codes, but for Windows this is not suitable .
for example platformio places libraries at:
C:\Users\noname\.platformio\packages\framework-ststm8spl\Libraries\STM8S_StdPeriph_Driver\
but the elf file gets a formatted string:
C:\Users
oname\.platformio\packages♀ramework-ststm8spl\Libraries\STM8S_StdPeriph_Driver\
similarly we can find another strings like:
C:\Users
oname\.platformio\packages○oolchain-sdcc◘in\..\include\stm8
local project files are not bypassed either, if they names starts from "taboo symbols":
src♀ont_arial.c
Bugs: #3200
Wiki: SDCC 4.3.0 Release
Wiki: SDCC 4.4.0 Release
Wiki: SDCC 4.5.0 Release
Wiki: SDCC 4.6.0 Release
I see this posted in the patch tracker, but no patch attached to the post.
Is there a patch coming? If not, I'll move the ticket to the bug tracker.
Sorry
I'm sorry, this is my first time on sourceforge and I haven't figured it out yet
I tried to find a solution myself, but I'm not sure if I can test the fix on all platforms
Please carry this over to errors.
thx a lot
Can you provide a minimal example that can be used to reproduce the issue?
The minimal example is
spl-blinkfor stm8sblue board from the platformio plugin for VSCode, with additional build options--out-fmt-elf --debug.But this path is too long for a developer to debugging.
So, I attached fully compiled with ready to burn binaries.
Preparation: extract archive and set current directory
220107-114753-spl-blinkLinking: to link "as is" the elf file, just call
!_linker.bat, but update theSDCC_DIRto your developing SDCC pathThen you may find target elf-file in:
.pio\build\stm8s003f3\firmware.elfVerification: The simplest way to check the correctness of paths - simple open this file in the notepad and check strings
if all ok - you should see strings like
C:\Users\User\.platformio\packages\tolchain-sdcc\bin\..\include\stm8but now you may see only
C:\Users\User\.platformio\packages oolchain-sdccin\..\include\stm8(see already attachedfirmware.elf)Debugging: If I'm correct, the issue in the
sdldstm8.exefile, so you may need to debug it. I prepared another!_linker_stm32.batfile (with.pio\build\stm8s003f3\firmware.lkand copy of originalstm8.liblibrary).You may use those settings and filed in your IDE while debugging.
Final verification:
It will be great if you will be able to build, burn and start debugging this firmware using VSCode + Platformio + STlink-v2 under Windows.
I hope I managed to make it as easy as possible to prepare the environment for debugging.
Ticket moved from /p/sdcc/patches/410/
Can't be converted:
The garbled file names are in
section .debug_lineandsection .debug_infoof the elf file.I believe that the former is generated by the function
dwWriteLineNumbersin SDCCdwarf2.c.The line
dwWriteString (srcfile->name, NULL);in there generates an!asciientry in the output. I do not see anything that could garble C escape sequences in SDCC itself, because the string ultimately winds up invsprintf, so I assume that the string constant parsing in SDAS does it. This would at lest make sense.Addendum:
The definition of
dwWriteStringcontains the following line, so I guess we should fix it in there.An example line from main.asm:
I can see how this could cause problems.
Last edit: Benedikt Freisen 2022-01-08
You right - the .rst files already have wrong
section .debug_lineandsection .debug_infoAnd the issue in the compiler, not in linker as I assumed before
Maybe something like this will do the trick?
(Warning: This patch is completely untested. I don't have a Windows machine handy.)
As far as I understand, the problem was stuff like \n in paths. You should be able to test that on GNU/Linux. \n can be part of a valid filename there.
This is the first thing that came to my mind and I wanted to check before posting a ticket.
And I tried to build the
sdcc.sln. Unfortunately the VS solution is old and don't generate files likesdldstm8.exe. And it was the main reason to create bug-ticket.I agree with @spth - the file names may contain
\nsymbol, but the sequence of characters "\n" should not be converted to single character "\x0D".The attached
*.rstalready contains some necessary examples (like \t \b \f) and you probably may try to link (by converting .bat to .sh files) .rst-files under Linux/OSX.Perhaps the problem may turn out to be much deeper - probably .rst files may be corrupted if they contain files with names/paths containing non-printable characters. By the way, the most of compilers have strong restrictions for names - not only "printable characters", but some for ANSI only.
Last edit: BOBAH 2022-01-08
This (linking .rel to .elf) will not fix the issue, because the .rel already corrupted.
So, as wrote @roybaer, should be fixed compiler.
Unfortunately I cannot build full staff of SDCC for Windows (in Visual Studio) by myself to check his patch.
Last edit: BOBAH 2022-01-09
I spent 3 days, but I could not prepare at least some working environment for the build binaries for Windows.
/usr/bin/) and cannot find other files (executable and headers+libs), so build always left with "file not found" error_WIN32(andWIN32) defines that related to VS but not Cygwin (__CYGWIN__), but if add all necessary defines (about 5pcs), the liking failed with errors - not found_vsnprintfand some funcs from Win32APIbooststops support of cross building and cannot be foundI have some ideas how to improve the SDCC (for example: remove dead functions at link time), but due to insurmountable obstacles consisting of a "forest of crutches", I just cannot start checking my ideas.
So sad with this project, that I want to go back to IAR, COSMIC or write a STM8-backend for LLVM myself.
Truth be told, if using a Linux system is an option you have, doing so is by far the easiest route to success as far as SDCC development is concerned.
Actually, I do not even know whether any active project member does SDCC development in Windows.
As Philipp pointed out, my patch can probably be tested with funny file names in Linux, because a Linux file name is allowed contain backslashes. Unfortunately, I have not had time to do it yet.
Off topic / regarding cross compiling: Do you know the MXE environment?
I have never used it with SDCC, but cross-compiling a few smaller programs was pleasantly painless.
I mostly use Debian GNU/Linux (though I also once in a while use OpenBSD or FreeBSD). Last time I used SDCC on Windows (years ago), I used Cygwin. That worked fine for me (but I used SDCC from within Cygwin, calling it from Makefiles, like I would in GNU/Linux).
It should be possible to build SDCC via the Microsoft Visual Studio. In fact, the language dialect in which SDCC is written was chosen to make this possible: https://sourceforge.net/p/sdcc/wiki/Language%20dialects%20used%20in%20SDCC/
If there are issues, they should be fixed. AFAIR, @maartenbrock used to have a look at such issues years ago.
Have you tried doing the snapshot build process locally? https://sourceforge.net/p/sdcc/wiki/HOWTO%20Make%20Snapshot%20Builds%20on%20the%20Developer%20Machine/ documents it. AFAIK, there should be a configuration (hostname.mk) for the windows builds as used in the compile farm, too.
The compiler farm cross compiles the Windows snapshots from Linux,, so this would not necessarily be a good approach for building sdcc from within Windows itself. Would be much easier just to fix the problem (escape the backslashes or don't use the .ascii pseudo op) and just wait for a new snapshot.
Years ago I used to use MSVC to build and debug SDCC. But I must admit that lately I don't find much time for this project. So, I'm sure the msvc solution is far behind.
But since this problem seems present in our GCC cross-compiled binaries, it is not related to MSVC.
Diff:
Related
Bugs: #3200
Thanks all for responses,
@roybaer, this project is used not only under Linux, but also in other OSs that can start Platformio and / or VSCode + Platformio-plugin as well as Arduino. If you look from this point of view, then this project has chances to be in demand in wide circles (and not only in the context of STM8, which surpasses AVR in characteristics and price, and at the same time is as close to electrical characteristics as possible). But there is one drawback: SDCC is pure-C, while Arduino-like projects are C++.
Relative to MXE - it also uses Linux (Unix-like OSes) with MinGW. And because the SDCC requires Boost during building, compilation (i.e. even configuration) will fail due to leak of Boost for target OS (i.e. leak of cross-compiled Boost for Windows)
@spth, I agreed, few years ago, mingw was mingw32 and Boost has support of cross compilation for mingw. But it was few years ago.
Regarding building on MS VS - yes, it possible, I even can got few workable files, but not full staff of binaries. VS projects required that developer must add to the project file (
.vcxproj) all used files - it cannot use*.cmask ;)VS may build, launch and debug cross-compilation projects, like for Android, OSx, Linux, some embedded (like ARM), supported few build system, like CMake. But not gnu-make.
It means, if you'd like to use MSVC, you should create MSVC project and highlight all necessary files name-by-name. And because nobody didn't update all
.vcxproj(and add some new) during long time, so VS projects are outdated (or as I wrote "old").Regarding "snapshot build process " as well as "hostname.mk", again - configuration cannot find Boost, because it stop support of cross build some time ago.
It took a long time, but I managed to overcome all obstacles :)
waitfunction for execution of sub processes, which is not supported by mingwrealpath()(as well asargv[0]) to/usr/bin/folder. But it's not a problem, because it's "virtual path" (similar to/cygdrive/c/and so). When application tried open or execute files, cygwinXXX.dlls convert this path to actual native pathsh.exe(i.e. bash!!! wtf!). So,sh.exealso should be copied to the folder, if you try to make portable bundle.C:\Windows\bla-bla\as wellC:/Windows/bla-bla/and evenc://winDoWs\\bLA-bla/, so we may preserve UNIX-like path inside application (i.e.#ifdef _WIN32 ...is useless for Cygwin in the most of cases)gdb) also correctly handles pathssdccconf_h_dir_separator="/"argument without any issuesThe final configuration of SDCC project under Windows and Cygwin is:
And do not forget to apply the attached patch.
That mostly exclude Cygwin from the Native Win32 checks like
This fix will build .asm files with the unix-like paths:
Conclusion: The bug may be considered fixed for Windows (to some extent, because used Windows native handling of
/as well as\)Last edit: BOBAH 2022-01-15
Yes! I did it!
But for STM8 and as proof of concept
The results are the following, where "original" SDCC is 4.1.0 #12072 (MINGW64):
"Hello word!" from the box:
**With small optimizations (just add
static inlinebefore all included functions)**
PS:
___str_0is parameter (path to the source file) ofassert_failed, and both of then (___str_0withassert_failed) were stripped because SDCC statically check the code and find it as unusedmaincode, where all functions are inline:took the form:
The results are looks great!
Of course, most likely it would be so if this message was in any way related to this topic as I started.
Sorry for offtop
I added string escaping to dwWriteString in [r12964], because it was evidently missing, anyway.
There is a high likelihood that it fixes this bug. Please retest.