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

Cross compilation issue #31

Closed
ikoes opened this issue Apr 9, 2016 · 6 comments
Closed

Cross compilation issue #31

ikoes opened this issue Apr 9, 2016 · 6 comments

Comments

@ikoes
Copy link

ikoes commented Apr 9, 2016

Hello guys,

Trying to cross compile the examples of the develop repository I got stucked with a rpl_malloc issue.

Basically I've done the following:

$ git clone https://github.com/raspberrypi/tools
$ cd libcoap
$./autogen.sh
$./configure --host=arm-linux-gnuabihf --disable-documentation
$ make

Then the command exit with this error
undefined reference to "rpl_malloc"

I found that setting the following env variable solved the problem:
$ export ac_cv_func_malloc_0_nonnull=yes

I don't know if that is an issue or not but it wasn't straightforward how to get it solved.

Thank you for your work.

FedBerg.

@obgm
Copy link
Owner

obgm commented Apr 12, 2016

Looks like this is caused by autoconf's AC_FUNC_MALLOC. I think that
libcoap should be able to go without in the long run. My proposed fix
therefore is as simple as the following:

diff --git a/configure.ac b/configure.ac
index 31158d8..1cf082e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -276,7 +276,6 @@ AC_TYPE_SIZE_T
 AC_TYPE_SSIZE_T

 # Checks for library functions.
-AC_FUNC_MALLOC
 AC_CHECK_FUNCS([memset select socket strcasecmp strrchr getaddrinfo \
                 strnlen])

@ikoes
Copy link
Author

ikoes commented Apr 12, 2016

Hello guys,

For now I've solved changing (as suggested here Link):
AC_FUNC_MALLOCto AC_CHECK_FUNCS([malloc])

I wil test it better as soon as I can.

@obgm
Copy link
Owner

obgm commented Apr 13, 2016

ikoes notifications@github.com writes:

I have updated my local repository and tried to rebuild without
exporting the env variable as explained before.

By the way the result is the same:

Please note that the proposed patch is not yet applied to the code in
the repository. It was supposed to be (tested and) discussed.

@obgm
Copy link
Owner

obgm commented Apr 13, 2016

ikoes notifications@github.com writes:

For now I've solved changing:
AC_FUNC_MALLOCto AC_CHECK_FUNCS([malloc])

This will fix the compilation issue. The question I had raised was
whether or not this is the right thing to do.

@tijuca
Copy link
Contributor

tijuca commented Apr 22, 2016

The error that happen while cross compiling is quite logical if you know what the check AC_FUNC_MALLOC is made for. The behavior isn't really wrong (for me) because autoconf can't really test the created code due it's for another platform. Some nice explanation about the whole problem can be found here:
http://wiki.buici.com/xwiki/bin/view/Programing+C+and+C%2B%2B/Autoconf+and+RPL_MALLOC

But as long as libcoap uses malloc from the libc we need a check for the proper implementation for this cases. So removing AC_FUNC_MALLOC isn't solving the problem. We need at least a check for a malloc functionality which can be done by AC_CHECK_FUNC(S) like suggested above. So would change the autoconf check to something like this:

diff --git a/configure.ac b/configure.ac
index 7f2ff90..f4452ac 100644
--- a/configure.ac
+++ b/configure.ac
@@ -276,9 +276,8 @@ AC_TYPE_SIZE_T
 AC_TYPE_SSIZE_T

 # Checks for library functions.
-AC_FUNC_MALLOC
 AC_CHECK_FUNCS([memset select socket strcasecmp strrchr getaddrinfo \
-                strnlen])
+                strnlen malloc])

 # Check if -lsocket -lnsl is required (specifically Solaris)
 AC_SEARCH_LIBS([socket], [socket])

After this you will get cross compiled binaries like native non cross builds.

$ PATH=/home/carsten/gitprojects/tools/arm-bcm2708/arm-bcm2708-linux-gnueabi/bin/:$PATH
$ ./autogen.sh
....
$ ./configure --host=arm-bcm2708-linux-gnueabi --disable-documentation
$ ./configure --host=arm-bcm2708-linux-gnueabi --disable-documentation
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for arm-bcm2708-linux-gnueabi-strip... arm-bcm2708-linux-gnueabi-strip
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for arm-bcm2708-linux-gnueabi-gcc... arm-bcm2708-linux-gnueabi-gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... yes
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether arm-bcm2708-linux-gnueabi-gcc accepts -g... yes
checking for arm-bcm2708-linux-gnueabi-gcc option to accept ISO C89... none needed
checking whether arm-bcm2708-linux-gnueabi-gcc understands -c and -o together... yes
checking for style of include used by make... GNU
checking dependency style of arm-bcm2708-linux-gnueabi-gcc... gcc3
checking for arm-bcm2708-linux-gnueabi-ar... arm-bcm2708-linux-gnueabi-ar
checking the archiver (arm-bcm2708-linux-gnueabi-ar) interface... ar
checking build system type... x86_64-pc-linux-gnu
checking host system type... arm-bcm2708-linux-gnueabi
checking how to print strings... printf
checking for a sed that does not truncate output... /bin/sed
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for fgrep... /bin/grep -F
checking for ld used by arm-bcm2708-linux-gnueabi-gcc... /home/carsten/gitprojects/tools/arm-bcm2708/arm-bcm2708-linux-gnueabi/arm-bcm2708-linux-gnueabi/bin/ld
checking if the linker (/home/carsten/gitprojects/tools/arm-bcm2708/arm-bcm2708-linux-gnueabi/arm-bcm2708-linux-gnueabi/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /home/carsten/gitprojects/tools/arm-bcm2708/arm-bcm2708-linux-gnueabi/bin//arm-bcm2708-linux-gnueabi-nm -B
checking the name lister (/home/carsten/gitprojects/tools/arm-bcm2708/arm-bcm2708-linux-gnueabi/bin//arm-bcm2708-linux-gnueabi-nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking how to convert x86_64-pc-linux-gnu file names to arm-bcm2708-linux-gnueabi format... func_convert_file_noop
checking how to convert x86_64-pc-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /home/carsten/gitprojects/tools/arm-bcm2708/arm-bcm2708-linux-gnueabi/arm-bcm2708-linux-gnueabi/bin/ld option to reload object files... -r
checking for arm-bcm2708-linux-gnueabi-objdump... arm-bcm2708-linux-gnueabi-objdump
checking how to recognize dependent libraries... pass_all
checking for arm-bcm2708-linux-gnueabi-dlltool... no
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for arm-bcm2708-linux-gnueabi-ar... (cached) arm-bcm2708-linux-gnueabi-ar
checking for archiver @FILE support... @
checking for arm-bcm2708-linux-gnueabi-strip... (cached) arm-bcm2708-linux-gnueabi-strip
checking for arm-bcm2708-linux-gnueabi-ranlib... arm-bcm2708-linux-gnueabi-ranlib
checking command to parse /home/carsten/gitprojects/tools/arm-bcm2708/arm-bcm2708-linux-gnueabi/bin//arm-bcm2708-linux-gnueabi-nm -B output from arm-bcm2708-linux-gnueabi-gcc object... ok
checking for sysroot... no
checking for a working dd... /bin/dd
checking how to truncate binary pipes... /bin/dd bs=4096 count=1
checking for arm-bcm2708-linux-gnueabi-mt... no
checking for mt... mt
configure: WARNING: using cross tools not prefixed with host triplet
checking if mt is a manifest tool... no
checking how to run the C preprocessor... arm-bcm2708-linux-gnueabi-gcc -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if arm-bcm2708-linux-gnueabi-gcc supports -fno-rtti -fno-exceptions... no
checking for arm-bcm2708-linux-gnueabi-gcc option to produce PIC... -fPIC -DPIC
checking if arm-bcm2708-linux-gnueabi-gcc PIC flag -fPIC -DPIC works... yes
checking if arm-bcm2708-linux-gnueabi-gcc static flag -static works... yes
checking if arm-bcm2708-linux-gnueabi-gcc supports -c -o file.o... yes
checking if arm-bcm2708-linux-gnueabi-gcc supports -c -o file.o... (cached) yes
checking whether the arm-bcm2708-linux-gnueabi-gcc linker (/home/carsten/gitprojects/tools/arm-bcm2708/arm-bcm2708-linux-gnueabi/arm-bcm2708-linux-gnueabi/bin/ld) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking whether C compiler accepts -Wlogical-op... yes
checking whether C compiler accepts -fdiagnostics-color... no
checking whether the linker accepts -Wl,--version-script=./libcoap-1.map... yes
checking for ctags... /usr/bin/ctags
checking assert.h usability... yes
checking assert.h presence... yes
checking for assert.h... yes
checking arpa/inet.h usability... yes
checking arpa/inet.h presence... yes
checking for arpa/inet.h... yes
checking limits.h usability... yes
checking limits.h presence... yes
checking for limits.h... yes
checking netdb.h usability... yes
checking netdb.h presence... yes
checking for netdb.h... yes
checking netinet/in.h usability... yes
checking netinet/in.h presence... yes
checking for netinet/in.h... yes
checking for stdlib.h... (cached) yes
checking for string.h... (cached) yes
checking for strings.h... (cached) yes
checking sys/socket.h usability... yes
checking sys/socket.h presence... yes
checking for sys/socket.h... yes
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking time.h usability... yes
checking time.h presence... yes
checking for time.h... yes
checking for unistd.h... (cached) yes
checking sys/unistd.h usability... yes
checking sys/unistd.h presence... yes
checking for sys/unistd.h... yes
checking syslog.h usability... yes
checking syslog.h presence... yes
checking for syslog.h... yes
checking for size_t... yes
checking for ssize_t... yes
checking for memset... yes
checking for select... yes
checking for socket... yes
checking for strcasecmp... yes
checking for strrchr... yes
checking for getaddrinfo... yes
checking for strnlen... yes
checking for malloc... yes
checking for library containing socket... none required
checking for library containing inet_ntop... none required
checking for library containing clock_gettime... -lrt
checking operating system... Linux
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating doc/Makefile
config.status: creating examples/Makefile
config.status: creating examples/coap-client.txt
config.status: creating examples/coap-server.txt
config.status: creating examples/coap-rd.txt
config.status: creating include/coap/coap.h
config.status: creating tests/Makefile
config.status: creating libcoap-1.pc
config.status: creating coap_config.h
config.status: coap_config.h is unchanged
config.status: executing depfiles commands
config.status: executing libtool commands

libcoap configuration summary:
      libcoap package version : "4.1.2"
      libcoap library version : "0.0.0"
      libcoap API version     : "1"
      host system             : "arm-bcm2708-linux-gnueabi"
      build documentation     : "no"
      build unit test binary  : "no"
      build examples          : "yes"
             -->  use a2x     : "no"
$ make -j4
....
$ file examples/.libs/coap-client
examples/.libs/coap-client: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.3, for GNU/Linux 3.1.9, not stripped

obgm pushed a commit that referenced this issue Apr 25, 2016
The error that happen while cross compiling is quite logical if you
know what the check AC_FUNC_MALLOC is made for. The behavior isn't
really wrong (for me) because autoconf can't really test the created
code due it's for another platform. Some nice explanation about the
whole problem can be found here:
http://wiki.buici.com/xwiki/bin/view/Programing+C+and+C%2B%2B/Autoconf+and+RPL_MALLOC

As long as libcoap uses malloc from the libc we need a check for
the proper implementation for this cases. So removing AC_FUNC_MALLOC
isn't solving the problem. We need at least a check for a malloc
functionality which can be done by AC_CHECK_FUNC(S).
@obgm
Copy link
Owner

obgm commented Apr 25, 2016

Fair enough. Although AC_FUNC_MALLOC obviously has its value here, I have dropped it in favor of tijuca's patch. All uses of coap_malloc() that invoke the system's malloc() function should already pass a value greater than zero but I did not review the entire code to ensure this.

@obgm obgm closed this as completed Apr 25, 2016
obgm pushed a commit that referenced this issue Apr 18, 2017
The error that happen while cross compiling is quite logical if you
know what the check AC_FUNC_MALLOC is made for. The behavior isn't
really wrong (for me) because autoconf can't really test the created
code due it's for another platform. Some nice explanation about the
whole problem can be found here:
http://wiki.buici.com/xwiki/bin/view/Programing+C+and+C%2B%2B/Autoconf+and+RPL_MALLOC

As long as libcoap uses malloc from the libc we need a check for
the proper implementation for this cases. So removing AC_FUNC_MALLOC
isn't solving the problem. We need at least a check for a malloc
functionality which can be done by AC_CHECK_FUNC(S).

(cherry picked from commit 04d806f)
This issue was closed.
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