Skip to content

newlib-nano: fix include directory#9216

Closed
toonst wants to merge 12 commits intoRIOT-OS:masterfrom
OTAkeys:pr/newlib-nano_incl_dir
Closed

newlib-nano: fix include directory#9216
toonst wants to merge 12 commits intoRIOT-OS:masterfrom
OTAkeys:pr/newlib-nano_incl_dir

Conversation

@toonst
Copy link
Copy Markdown
Member

@toonst toonst commented May 28, 2018

Contribution description

Adding the nano.specs file to CFLAGS make sure the correct include directory is found. This way we don't have to explicitly add the include directory.

Issues/PRs references

Fixes #9214
Fixes PR #9080
Alternative to #9215

Copy link
Copy Markdown
Member

@jnohlgard jnohlgard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you test this on clang as well? IIRC we needed some extra handling for that

@jcarrano
Copy link
Copy Markdown
Contributor

Works for me on Arch. I'm closing #9215 as it is hacky.

@toonst
Copy link
Copy Markdown
Member Author

toonst commented May 28, 2018

@gebart No I did not. And you're right, it needs some extra handling. I'm looking into it.

@jcarrano
Copy link
Copy Markdown
Contributor

jcarrano commented May 29, 2018

@toonst Is it acceptable to fall back to what your previous PR (#9080 ) did if the toolchain is clang? And in that case, could we force a failure if nano's headers are not found, so that the error becomes more evident?

@pwillem
Copy link
Copy Markdown

pwillem commented May 29, 2018

@smlng
Copy link
Copy Markdown
Member

smlng commented May 29, 2018

works on macOS

@smlng smlng added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Platform: ARM Platform: This PR/issue effects ARM-based platforms CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR OS: Mac OS X Host OS: This PR/issue concerns usage of RIOT with Mac OS X as a host system labels May 29, 2018
@kYc0o
Copy link
Copy Markdown
Contributor

kYc0o commented May 29, 2018

CCN package is broken with this PR... I'd suggest to revert to the original state and then try another option for this?

@smlng
Copy link
Copy Markdown
Member

smlng commented May 30, 2018

can we get this merged, need this to compile arm based boards on macOS!!

@kYc0o
Copy link
Copy Markdown
Contributor

kYc0o commented May 30, 2018

@smlng have you seen Murdock's output?

@smlng
Copy link
Copy Markdown
Member

smlng commented May 30, 2018

ah damn, but its only ccn-lite 😬 otherwise we should think about reverting #9080?

@smlng
Copy link
Copy Markdown
Member

smlng commented May 30, 2018

so its a problem with all external packages?

@toonst toonst force-pushed the pr/newlib-nano_incl_dir branch from 4c5967a to 77e5081 Compare May 30, 2018 08:40
@toonst
Copy link
Copy Markdown
Member Author

toonst commented May 30, 2018

Sorry it took this long.
I made some extra checks for the existence of a newlib.h file and error when trying to compile for native. I'm looking at getting newlib to work on linux, so if that is working we can remove the check.
Could you test if this is working properly on OSX? Suggestions welcome!

@smlng
Copy link
Copy Markdown
Member

smlng commented May 30, 2018

still works on macOS but also still get error when compiling ccn-lite-relay for any arm board.

@jcarrano
Copy link
Copy Markdown
Contributor

@smlng @kYc0o What happens with CCN is that the CFLAGS get passed twice to the compiler.

@kYc0o
Copy link
Copy Markdown
Contributor

kYc0o commented May 30, 2018

I see, then it needs a check in the pkg makefile. @toonst do you mind to provide a patch for that also? Otherwise this will be broken and cannot be merged... It can also come in a separated PR, I can do it later if needed.

@toonst
Copy link
Copy Markdown
Member Author

toonst commented May 30, 2018

@kYc0o I don't know cmake, but if I just remove the RIOT CFLAGS it seems to be fine. You think this is OK?

@smlng
Copy link
Copy Markdown
Member

smlng commented May 30, 2018

@toonst note that it is not just ccn-lite, jerryscript, relic are not working, too. It seems that all apps that use external third party package won't compile, bc the CFLAGS are passed 2 times which causes the error.

@smlng
Copy link
Copy Markdown
Member

smlng commented May 30, 2018

@jcarrano
Copy link
Copy Markdown
Contributor

@smlng @toonst What if -specs is made part of the CC variable instead of a CFLAG? In a way it mitght even make more sense, because even if packages could override CFLAGS, the specs flag defines lower level compilation and linking details which are not supposed to change. It would also make it easier with clang, since specs is not a valid flag for clang.

@toonst toonst force-pushed the pr/newlib-nano_incl_dir branch from 20cf3fd to 2c92bff Compare May 30, 2018 12:26
@kYc0o
Copy link
Copy Markdown
Contributor

kYc0o commented May 30, 2018

@toonst have you tried what @jcarrano suggests? The packages still failing 🙁

@toonst
Copy link
Copy Markdown
Member Author

toonst commented May 30, 2018

@jcarrano @kYc0o adding the specs flag to CC doesn't work for cmake:

  The CMAKE_C_COMPILER:
    arm-none-eabi-gcc -specs=nano.specs
  is not a full path and was not found in the PATH.

@kYc0o
Copy link
Copy Markdown
Contributor

kYc0o commented May 30, 2018

I see... What do you think then on reverting #9080 while we find a proper solution?

@toonst toonst force-pushed the pr/newlib-nano_incl_dir branch from 6d567a2 to e751ac3 Compare June 12, 2018 15:47
* remove check for native board
* add Werror so using specs fails for clang
* remove useless comments
@tcschmidt
Copy link
Copy Markdown
Member

Do all tests complete now? Are we ready to finish the review?

NEWLIB_NANO_INCLUDE_DIR ?= $(firstword $(wildcard $(addprefix $(NEWLIB_INCLUDE_DIR)/, newlib-nano nano)))
ifneq ($(NEWLIB_NANO_INCLUDE_DIR),)
# newlib-nano overrides newlib.h and its include dir should therefore go before
# the regular system include dirs, but after the other newlib includes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still not seeing why the nano include dir should go after the newlib include. newlib-nano overrides the newlib.h and therefore should go before newlib include or otherwise we will get the newlib.h from the regular newlib include directory.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I missed your first comment on it. Fixed!

.PHONY: all

export RIOT_CFLAGS = $(CFLAGS) $(INCLUDES)
RIOT_CFLAGS := $(INCLUDES)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work? Isn't $(INCLUDES) empty at this point? Should this be = instead of :=?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it is called with make -C pkg/PKGNAME the variable was already set from environment variable.
However, there is not reasons to set it with := either.

Toon Stegen added 2 commits June 14, 2018 21:57
we don't need to search for newlib include dirs manually when using the
nano.specs file
include ../Makefile.tests_common

# MIPS based boards are black listed due to some issue with newlib and _Atomic
BOARD_BLACKLIST := mips-malta pic32-clicker pic32-wifire
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: this should be removed, if someone has solution for the MIPS toolchain. It seems that some include paths are mixed up and the mips-gcc cannot find some system header files?!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The difference between master and this pr with make info-build:

diff -u info-build-master  info-build-pr 
--- info-build-master   2018-06-19 13:47:58.983288813 +0200
+++ info-build-pr       2018-06-19 13:48:08.447320615 +0200
@@ -35,6 +35,8 @@
 FEATURES_CONFLICT_MSG: 
 
 INCLUDES: 
+       -isystem  
+       /opt/mips-mti-elf/2016.05-03/mips-mti-elf/include  
        -I/home/harter/work/git/RIOT/core/include  
        -I/home/harter/work/git/RIOT/drivers/include  
        -I/home/harter/work/git/RIOT/sys/include 

I also get warnings two times when doing info-build:

make -C tests/rmutex BOARD=pic32-wifire info-build > info-build-pr
/home/harter/work/git/RIOT/makefiles/libc/newlib.mk:51: newlib.h not found, guessing newlib include path from gcc path
/home/harter/work/git/RIOT/makefiles/libc/newlib.mk:51: newlib.h not found, guessing newlib include path from gcc path

Copy link
Copy Markdown
Member

@jnohlgard jnohlgard Jun 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is your newlib installation located? (newlib.h)
What distro?
Edit: never mind, I didn't see the context was mips-mti-elf

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found that the two times warning comes from $(MAKE) info-boards-supported being called during make info-build.


I use ubuntu 16.04 and I installed the mips-mti-elf as explained in the Wiki I think:

$ /opt/mips-mti-elf/2016.05-03/bin/mips-mti-elf-gcc --version
mips-mti-elf-gcc (Codescape GNU Tools 2016.05-03 for MIPS MTI Bare Metal) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

And I have a only this newlib.h in mips-mti-elf directory, no newlib-nano directory:

/opt/mips-mti-elf/2016.05-03/mips-mti-elf/include/newlib.h

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When compiling, I have errors in stdatomic.h and with the new change that puts -isystem ABC it looks like it is another stdatomic.h that is used:

I have these two:

/opt/mips-mti-elf/2016.05-03/mips-mti-elf/include/stdatomic.h
/opt/mips-mti-elf/2016.05-03/lib/gcc/mips-mti-elf/4.9.2/include/stdatomic.h

/usr/$(TARGET_ARCH)/include \
/usr/local/opt/$(TARGET_ARCH)*/$(TARGET_ARCH)/include \
/usr/local/opt/gcc-*/$(TARGET_ARCH)/include \
#
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment for the backslash terminated line was removed.

# newlib-nano overrides newlib.h and its include dir
# should therefore go before the other newlib includes.
NEWLIB_INCLUDES := -isystem $(NEWLIB_NANO_INCLUDE_DIR) $(NEWLIB_INCLUDES)
endif
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if there is no newlib-nano ?
Is it ok to ignore this as it was right now ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory, code that depends on having newlib-nano should test for the appropriate macros, so that compilation fails right away instead if causing weird errors.

Copy link
Copy Markdown
Contributor

@cladmi cladmi Jun 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From reading around, the difference between newlib and newlib-nano, should, according to https://community.nxp.com/thread/389086, almost only be code size, so with how things are usually used, no API dependency.
So there should not be any "dependency on newlib-nano" that should be tested in the code.
I would rely on the build system to report it.

However, my knowledge on the topic is limited.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The size and layout of some internal newlib variables and structs are affected, for example sizeof(struct reent). Using the newlib.h from normal newlib when linking against newlib nano will probably work without any errors, but waste RAM. The other way around will result in buffer overflow bugs that will be difficult to debug.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jcarrano Do you have some macros that could be checked to verify if newlib-nano is used ? I would like to verify that right now, some configuration are already broken and not using newlib-nano when requested.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cladmi check _WANT_REENT_SMALL

# but Clang, when cross-compiling, needs to be told where to find the headers
# for the system being built.
# We also add -nostdinc to avoid including the host system headers by mistake
# in case some header is missing from the cross tool chain
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ifeq section with the gcc case was removed and it adds a wrong -isystem directory for mips-gcc 4.9.2 on my computer.

It supplies /opt/mips-mti-elf/2016.05-03/mips-mti-elf/include/ which replaces /opt/mips-mti-elf/2016.05-03/lib/gcc/mips-mti-elf/4.9.2/include/

Which breaks compilation for mips in the rmutex example.

However, re-adding the ifeq would only solve my case but maybe not llvm as it would be using the wrong directory.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try if it works with the latest additions?

Copy link
Copy Markdown
Contributor

@cladmi cladmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel this is going a bit too far for a single PR and it starts having side effects. This makes it hard for me to get forward in reviewing everything.

Adding only the nano.specswhen supported in a separate PR would be already one step. Fixing the whole newlib include handling when nano.specs is not used and with llvm is another task would help the review.

I can do the split PR fixing the packages this afternoon.

@smlng
Copy link
Copy Markdown
Member

smlng commented Jun 22, 2018

this fixes (all) my issues on macOS with newlib, right now (2018-06-22) master is broken there

@smlng
Copy link
Copy Markdown
Member

smlng commented Jun 22, 2018

however, I also agree with @cladmi that we should introduces changes/fixes step-by-step, ie. nano-spec, include-dir, and llvm support.

Toon Stegen added 2 commits June 26, 2018 14:23
also
* give error when no newlib directory is found
* add search for newlib/nano directory
original author: cgundogan
@toonst
Copy link
Copy Markdown
Member Author

toonst commented Jun 26, 2018

Closed in favor of #9394 and #9415

@toonst toonst closed this Jun 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR OS: Mac OS X Host OS: This PR/issue concerns usage of RIOT with Mac OS X as a host system Platform: ARM Platform: This PR/issue effects ARM-based platforms Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

make: compiling is broken for any ARM platform on OS X.

9 participants