5

I'm here because I can't solve my problem; in fact I'm making a C project with the arm-none-eabi-gcc compiler in Eclipse CDT C/C++ IDE(it's for the STM32 embedded card), and I have implemented PolarSSL to create an HTTPS server :

I saw in many forums that I need to delete the printf, malloc, file, path to avoid this error(indeed I'm on an embedded project so these functions are prohibited!). But these errors stay here even if I delete all these functions! So now I don't know how solve these errors, so could you help me please?

Thank you for your help.

'Building file: ../.metadata/.plugins/org.eclipse.cdt.make.core/specs.c'
'Invoking: Cross GCC Compiler'
arm-none-eabi-gcc -DARP_CACHE_SIZE=4 -D_kill -D_getpid -D_cert -DUSE_IPV4 -DUSE_IPV6 -DNDP_CACHE_SIZE=4 -DHARDWARE_ETH_TX_CRC -DHARDWARE_ETH_RX_CRC -DUSE_STDPERIPH_DRIVER -DUSE_TCP -DHSE_VALUE=25000000 -DSTM32F2XX -DUSE_MII -I"C:\Sebastien\Sujet_1_ServeurWeb\Projet_1/test_serverweb_v0/src" -I"C:\Sebastien\Sujet_1_ServeurWeb\Projet_1/test_serverweb_v0/src/Library_StackIP/Driver_phyter_f2" -I"C:\Sebastien\Sujet_1_ServeurWeb\Projet_1/test_serverweb_v0/src/stm32f2xx" -I"C:\Sebastien\Sujet_1_ServeurWeb\Projet_1/test_serverweb_v0/src/urts" -I"C:\Sebastien\Sujet_1_ServeurWeb\Projet_1/test_serverweb_v0/src/ethernet" -I"C:\Sebastien\Sujet_1_ServeurWeb\Projet_1/test_serverweb_v0/src/agilia" -I"C:\Sebastien\Sujet_1_ServeurWeb\Projet_1/test_serverweb_v0/src/Service_HttpServeur" -I"C:\Sebastien\Sujet_1_ServeurWeb\Projet_1/test_serverweb_v0/src/Library_StackIP" -I"C:\Sebastien\Sujet_1_ServeurWeb\Projet_1/test_serverweb_v0/src/include/polarssl" -I"C:\Sebastien\Sujet_1_ServeurWeb\Projet_1/test_serverweb_v0/src/include" -I"C:\Sebastien\Sujet_1_ServeurWeb\Projet_1/test_serverweb_v0/src/library" -I"C:\Program Files\AIM\uOne\Tools\eclipse\..\..\CMSIS_V3P00\CMSIS\Include" -I"C:\Program Files\AIM\uOne\Tools\eclipse\..\..\CMSIS_V3P00\Device\ST\STM32F2xx\Include" -I"C:\Program Files\AIM\uOne\Tools\eclipse\..\..\F2\inc" -I"C:\Sebastien\Sujet_1_ServeurWeb\Projet_1\test_serverweb\src\LibrarySSL" -I"C:\Program Files\AIM\uOne\Tools\eclipse\..\..\F2\StdPeriph_Driver\inc" -I"C:\Program Files\AIM\uOne\Tools\eclipse\..\..\F2\STM32_Ethernet\inc" -I"C:\AIM\uOne\F2\inc" -I"C:\AIM\uOne\F2\StdPeriph_Driver\inc" -O2 -g3 -Wall -c -fmessage-length=0 -mthumb -mcpu=cortex-m3 -mfix-cortex-m3-ldrd -mfloat-abi=softfp -fsigned-char -ffunction-sections -fdata-sections -fomit-frame-pointer -MMD -MP -MF".metadata/.plugins/org.eclipse.cdt.make.core/specs.d" -MT".metadata/.plugins/org.eclipse.cdt.make.core/specs.d" -o ".metadata/.plugins/org.eclipse.cdt.make.core/specs.o" "../.metadata/.plugins/org.eclipse.cdt.make.core/specs.c"
'Finished building: ../.metadata/.plugins/org.eclipse.cdt.make.core/specs.c'

'Building target: test_serverweb_v0'
'Invoking: Cross GCC Linker'
arm-none-eabi-gcc -static -L"C:\Program Files\AIM\uOne\Tools\eclipse\..\..\F2\lib" -L"C:\AIM\uOne\F2\lib" -L"C:\Program Files\AIM\uOne\Tools\eclipse\..\..\F2\StdPeriph_Driver\lib" -L"C:\Program Files\AIM\uOne\Tools\eclipse\..\..\F2\STM32_Ethernet\lib" -L"C:\AIM\uOne\F2\STM32_Ethernet\lib" -L"C:\AIM\uOne\F2\StdPeriph_Driver\lib" -mthumb -mcpu=cortex-m3 -fsigned-char -ffunction-sections -fdata-sections -Wl,-T,../ldscripts/flash.ld,-Map,Debug.map,--gc-sections -o "test_serverweb_v0"  ./src/urts/urts_init.o  ./src/stm32f2xx/startup_stm32f2xx.o ./src/stm32f2xx/system_stm32f2xx.o  ./src/library/aes.o ./src/library/aesni.o ./src/library/arc4.o ./src/library/asn1parse.o ./src/library/asn1write.o ./src/library/base64.o ./src/library/bignum.o ./src/library/blowfish.o ./src/library/camellia.o ./src/library/certs.o ./src/library/cipher.o ./src/library/cipher_wrap.o ./src/library/ctr_drbg.o ./src/library/debug.o ./src/library/des.o ./src/library/dhm.o ./src/library/ecdh.o ./src/library/ecdsa.o ./src/library/ecp.o ./src/library/ecp_curves.o ./src/library/entropy.o ./src/library/entropy_poll.o ./src/library/error.o ./src/library/gcm.o ./src/library/havege.o ./src/library/md.o ./src/library/md2.o ./src/library/md4.o ./src/library/md5.o ./src/library/md_wrap.o ./src/library/memory.o ./src/library/memory_buffer_alloc.o ./src/library/net.o ./src/library/oid.o ./src/library/padlock.o ./src/library/pbkdf2.o ./src/library/pem.o ./src/library/pk.o ./src/library/pk_wrap.o ./src/library/pkcs11.o ./src/library/pkcs12.o ./src/library/pkcs5.o ./src/library/pkparse.o ./src/library/pkwrite.o ./src/library/ripemd160.o ./src/library/rsa.o ./src/library/sha1.o ./src/library/sha256.o ./src/library/sha512.o ./src/library/ssl_cache.o ./src/library/ssl_ciphersuites.o ./src/library/ssl_cli.o ./src/library/ssl_srv.o ./src/library/ssl_tls.o ./src/library/threading.o ./src/library/timing.o ./src/library/version.o ./src/library/x509.o ./src/library/x509_create.o ./src/library/x509_crl.o ./src/library/x509_crt.o ./src/library/x509_csr.o ./src/library/x509write_crt.o ./src/library/x509write_csr.o ./src/library/xtea.o  ./src/agilia/agilia_VC.o ./src/agilia/agilia_VS.o ./src/agilia/agilia_init_uRTS.o ./src/agilia/agilia_login_sha1.o ./src/agilia/agilia_moteur_info.o ./src/agilia/agilia_targetId.o ./src/agilia/agilia_xbin_mem.o  ./src/Service_HttpServeur/AFS.o ./src/Service_HttpServeur/AgiliaGV.o ./src/Service_HttpServeur/Base64.o ./src/Service_HttpServeur/HtmlPage.o ./src/Service_HttpServeur/HtmlPageDynamic.o ./src/Service_HttpServeur/Http.o ./src/Service_HttpServeur/HttpServer.o ./src/Service_HttpServeur/HttpUsers.o ./src/Service_HttpServeur/MoteurHTTP.o ./src/Service_HttpServeur/StdAfx.o ./src/Service_HttpServeur/UTF8.o ./src/Service_HttpServeur/WebSite.o ./src/Service_HttpServeur/divers.o ./src/Service_HttpServeur/httpd.o ./src/Service_HttpServeur/mime.o ./src/Service_HttpServeur/sgf_sdcard.o  ./src/Library_StackIP/Driver_phyter_f2/drv_buffer.o ./src/Library_StackIP/Driver_phyter_f2/drv_mac.o ./src/Library_StackIP/Driver_phyter_f2/drv_phyter_f2.o ./src/Library_StackIP/Driver_phyter_f2/drv_stats.o  ./src/Library_StackIP/arp.o ./src/Library_StackIP/hntonh.o ./src/Library_StackIP/icmp.o ./src/Library_StackIP/icmpv6.o ./src/Library_StackIP/interface_ethernet.o ./src/Library_StackIP/ipv4.o ./src/Library_StackIP/ipv6.o ./src/Library_StackIP/sck_api.o ./src/Library_StackIP/tcp.o ./src/Library_StackIP/udp.o  ./src/config_user.o ./src/ethernet_init.o ./src/hardware_init.o ./src/main.o ./src/peripherals_config.o ./src/ressources.o ./src/ssl_init_uRTS.o ./src/systickDelay.o ./src/timer_uRTS.o  ./.metadata/.plugins/org.eclipse.cdt.make.core/specs.o    -lservice_strformat -lagcomethernet -ltest_syscalls_v2 -lagcore -lagstr -lagtrycatch -lagvariables -lcrc16_soft -lcrc32_f2 -lsha1_soft -lagmetadebug -lflash_f2 -ldrv_phyter_f2 -lservice_horodateur -lservice_httpServeur -lservice_socket -lservice_STM32 -lsysirq -lsysrtc_f2 -lurts -lurtscore -ltrap12 -ltrap12core -lsystime -lsystick -lstm32_stdperiph_driver -lstm32_ethernet -lRessources
c:/program files/aim/uone/tools/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib/armv7-m\libc.a(lib_a-signalr.o): In function `_kill_r':
signalr.c:(.text._kill_r+0xe): undefined reference to `_kill'
c:/program files/aim/uone/tools/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib/armv7-m\libc.a(lib_a-signalr.o): In function `_getpid_r':
signalr.c:(.text._getpid_r+0x0): undefined reference to `_getpid'
c:/program files/aim/uone/tools/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib/armv7-m\libc.a(lib_a-sbrkr.o): In function `_sbrk_r':
sbrkr.c:(.text._sbrk_r+0xc): undefined reference to `_sbrk'
collect2: ld returned 1 exit status
aim-make: *** [test_serverweb_v0] Error 1

**** Build Finished ****
user3463977
  • 61
  • 1
  • 2
  • 5
  • 1
    Does the platform have an OS, or is your application intended to be "freestanding" ? – wildplasser Mar 26 '14 at 11:50
  • thank you for your answers. i'm not compiling on command line : i'm in windows and i use the eclipse environment. the stm32 card didn't have an OS like i said just below ! so we can say that my application intended to be "freestanding" ! so these OS functions are useless for me... but i can't separate them easier... – user3463977 Mar 26 '14 at 16:33
  • 2
    The error messages are *plain text* - why do you need to post a picture!? – Clifford Mar 26 '14 at 20:17
  • You need to figure out where those functions are referenced - that should be clear in the error messages, but if not recursive grep is your friend. If they are referenced in library code you build but never use, perhaps you need a "-Wl,--gc-sections" build flag to cause the linker to prune unused code. – Chris Stratton Mar 26 '14 at 21:34
  • sorry clifford, i mean : give a copy of the screen of these error messages in eclipse ! i write here the 3 error messages : – user3463977 Mar 26 '14 at 22:39
  • @user3463977: Don't add the error messages as comments! Update your question. – Clifford Mar 27 '14 at 11:17
  • Add the complete build log (to the question), not just the error messages - we need to see how the linker was invokes at least. – Clifford Mar 27 '14 at 11:33
  • i update my first message with the "cross gcc linker invoking" ! what do you think about please ? regards, sebastien. – user3463977 Mar 27 '14 at 13:28
  • i add a typical message of my console for the "cross GCC compiler invoking" too : of course the message is the same for the other "building file" ! thank you very much for your help. – user3463977 Mar 27 '14 at 13:40

5 Answers5

1

I understand that these are OS functions necessary to use newlib (a standard c lib implementation). On a system which doesn't provide them (as @wildplasser said: no OS?) they apparently need to be defined explicitly. Perhaps this link helps: http://wiki.osdev.org/Porting_Newlib. I got there from http://balau82.wordpress.com/2010/12/16/using-newlib-in-arm-bare-metal-programs/.

Peter - Reinstate Monica
  • 15,048
  • 4
  • 37
  • 62
  • Firstly thank you for your answer. i'm working on windows 7, and my stm32 board didn't have an OS : so i flash my web server inside it. your 2nd document seems to be useful, thanks ! but in fact about my project, i don't need to use these functions like printf, etc... so i would delete these functions, but i don't know if it's possible for polarSSL ( otherwise i'm going to use newlib, but does it work on windows please ? ) thank you very much. – user3463977 Mar 26 '14 at 16:00
1

You do not need to "delete" anything in Newlib, and neither should you - and I don't think it will help - I wonder where you read that?

You need to provide the syscall stubs, although many of them can be empty functions, or at least return the error state, in case someone or something does inadvertently call them - they are to do with process control, memory allocation and stream I/O. These are almost certainly referenced indirectly by the third-party code you are using.

If you build Newlib as a static library, it will only link the code that is necessary to resolve symbols in your code, so if you are getting undefined references then you are calling something that depends on them.

What you should not do is compile and link the Newlib code directly to your application code - that will link a large amount of unused code and require you to supply otherwise unused stubs.

Clifford
  • 88,407
  • 13
  • 85
  • 165
  • I think the intent was to not use them at all, and remove the need for them to be resolved as dependencies - hopefully not be deleting them from the library, but rather by not using any functionality which requires them. – Chris Stratton Mar 26 '14 at 21:35
  • firstly thank you for your answers ! newlib has a linux dependance, isn't it ? like sys/ librairies ; in this website just below, we have newlib_stubs.c which have #include sys/stats.h, etc...so it will not work, isn't it ? ( i'm on windows ) http://stm32discovery.nano-age.co.uk/open-source-development-with-the-stm32-discovery/getting-newlib-to-work-with-stm32-and-code-sourcery-lite-eabi – user3463977 Mar 26 '14 at 22:56
  • moreover, if i absolutely need to use newlib, do i need to insert all the newlib source, like in this website just below, in my C project ? http://stm32discovery.nano-age.co.uk/open-source-development-with-the-stm32-discovery/getting-newlib-to-work-with-stm32-and-code-sourcery-lite-eabi – user3463977 Mar 26 '14 at 22:57
  • No, Newlib does not have Linux dependencies. It has a set of syscall stubs that you must provide to map the library to your system (Whether it uses a GPOS, RTOS or bare-metal). In the link you posted, read the comment above the `_fstat()` function - the naming is used for consistency with POSIX and the file itself is provided with the package discussed in the article (although it is not clear to me that that package is available for download). – Clifford Mar 26 '14 at 23:09
  • You have two choices. You can build a static libc.a library from the Newlib source that includes your syscall stubs, or you can build it without the syscalls, and compile an link the syscall code with your application. The latter is probably preferable if you do not intend to fully implement all the stubs, and you want a single library that will work on any Cortex-M based processor. If you already have a Newlib libc.a, then you clearly need to do the latter in any case unless you want to rebuild the library. – Clifford Mar 26 '14 at 23:12
  • Minimal implementations of all the syscall stubs are provided in the [Newlib documentation](https://sourceware.org/newlib/libc.html#Syscalls). They are very simple. I recommend that you at least implement `sbrk` since third party libraries you might use may expect a working heap. – Clifford Mar 26 '14 at 23:18
  • i took the _kill, _getpid and _sbrk, create a static library .a and link it with my project but it doesn't work... ( i had the .d related too ) – user3463977 Mar 27 '14 at 10:58
  • Post the *complete* build log - update the question do not add as comments. These functions are clearly not being linked, so you need to post all linker and compiler diagnostic information to get a diagnosis. I suggest you simplify things and add the syscalls source to your project rather than a separate static library. If you have a separate static library for syscalls and libc.a, you will need to ensure that the syscalls library appears in the link order ahead of libc.a, or use [*grouping*](http://stackoverflow.com/questions/5651869/gcc-start-group-and-end-group-command-line-options) – Clifford Mar 27 '14 at 11:31
  • I have a `Make` project with similar issue. On my machine the code compiles. However, my colleague can cot compile on his machine - `undefined reference to _getpid` error is returned. Does anyone have a clue as to why this could be the case: i.e. why the code compiles on one machine but not on the other? – mercury0114 Nov 27 '20 at 11:43
  • @mercury0114 SO is not a discussion forum. If you have a question, post a question. By posting a comment, the only people likely to see it on a 6 year old answer are me and the OP. Also your problem is most likely not that similar to this issue where the syscalls were not implemented. Rather, you are clearly not linking in the same object code or libraries across the two systems. Possibly there are dependencies on environment variables that differ across the two. A text comparison of the build log from a clean build may help identify differences. – Clifford Nov 27 '20 at 12:36
1

According to the forum try adding:

-specs=nosys.specs

Andre Hofmeister
  • 3,185
  • 11
  • 51
  • 74
0

Don't compile with option -nostartfiles when you are compiling to MCUs.

Traummaennlein
  • 474
  • 5
  • 12
-1

In my case I was compiling with C++ and turning exceptions off solved my problem. Add -fno-exceptions to your compile flags. You may also want to turn off Run Time Type Information (RTTI) as well, i.e. -fno-rtti.

CPPFLAGS += -fno-exceptions -fno-rtti

artronics
  • 1,399
  • 2
  • 19
  • 28