Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 672260 - sys-libs/newlib: xtensa support
Summary: sys-libs/newlib: xtensa support
Status: RESOLVED WONTFIX
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal enhancement
Assignee: Gentoo Crossdev team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-11-29 22:49 UTC by Thomas Capricelli
Modified: 2023-01-06 02:37 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Capricelli 2018-11-29 22:49:29 UTC
xtensa doesn't seem supported yet by crossdev, typically:

sudo crossdev  xtensa-esp32-elf 
(...)
!!! WARNING - Cannot auto-configure CHOST xtensa-esp32-elf;
!!! You should edit 
!!! by hand to complete your configuration.
!!!  No LIBC is known for this target.
!!!  No KERNEL is known for this target.
 * Log: /var/log/portage/cross-xtensa-esp32-elf-binutils.log
 * Emerging cross-binutils ...                                                                                                                                        [ ok ]
 * Log: /var/log/portage/cross-xtensa-esp32-elf-gcc-stage1.log
 * Emerging cross-gcc-stage1 ...                                                                                                                                      [ ok ]
 * Log: /var/log/portage/cross-xtensa-esp32-elf-newlib.log
 * Emerging cross-newlib ...

 * error: newlib failed :(
 * 

The newlib error is:
*** Newlib does not support CPU xtensa
Comment 1 Sergei Trofimovich (RETIRED) gentoo-dev 2018-11-30 20:11:22 UTC
rumors say we have ancient newlib in the tree. Do you know if 3.0.0 supports xtensa? Or maybe you don't need libc at all, then 'crossdev -s1' would do.
Comment 2 Sergei Trofimovich (RETIRED) gentoo-dev 2018-12-02 23:44:14 UTC
(In reply to Sergei Trofimovich from comment #1)
> rumors say we have ancient newlib in the tree. Do you know if 3.0.0 supports
> xtensa? Or maybe you don't need libc at all, then 'crossdev -s1' would do.

I had a look at newlib and don't believe it supports newlib as a libc for xtensa upstream. What do people use for it?
Comment 3 Thomas Capricelli 2018-12-03 07:40:14 UTC
I'm not sure about what people use, and i'm not even sure i need newlib, but the way crossdev works is that it does

* gcc stage 1
* <some libc>
* gcc stage >1

And as a result i can't get a 'real' gcc because of the 'newlib' error.


According to what I see in tar.gz, newlib 2.2.0 doesn't have much for xtensa (only few lines in config.sub/config.guess), but newlib 2.5.0 has a lot more (include/xtensa*, include/elf/xtensa.h, include/Changelog...)

So maybe crossdev should use newlib 2.5.0 for xtensa ??
Comment 4 Sergei Trofimovich (RETIRED) gentoo-dev 2018-12-03 19:18:12 UTC
(In reply to Thomas Capricelli from comment #3)
> I'm not sure about what people use, and i'm not even sure i need newlib but
> the way crossdev works is that it does
> 
> * gcc stage 1
> * <some libc>
> * gcc stage >1
> 
> And as a result i can't get a 'real' gcc because of the 'newlib' error.

gcc stage1 is a real gcc. It just does not know any libc-specific stuff, like start files or dynamic loader implementation (which normally does not exist on bare metal).

What do you plan to compile with such a toolchain? Maybe we can infer libc from the use case.

> So maybe crossdev should use newlib 2.5.0 for xtensa ??

crossdev already does use newlib-2.5.0 (untill you pass -S which uses stable 2.2.0) and 2.5.0 fails the same.
Comment 5 Thomas Capricelli 2019-06-25 23:21:02 UTC
By 'real' i mean a stage4 (with c++).

The most obvious need for such a toolchain is to use the official SDK from espressif :

https://docs.espressif.com/projects/esp-idf/en/latest/get-started-cmake/linux-setup.html

Is uses/requires g++
Comment 6 Thomas Capricelli 2019-06-26 00:05:34 UTC
for the record, esp-idf uses newlib
Comment 7 Sergei Trofimovich (RETIRED) gentoo-dev 2019-06-26 06:32:32 UTC
(In reply to Thomas Capricelli from comment #6)
> for the record, esp-idf uses newlib

Which version? Is it an upstream newlib? So far I found no versions that can compile for this target.
Comment 8 Thomas Capricelli 2019-06-26 13:43:09 UTC
They have a copy of newlib in their sdk under components/newlib/, i assume it's heavily patched.

In .gitmodules, they have:

    [submodule "newlib_xtensa-2.2.0"]
    path = newlib_xtensa-2.2.0
    url = ssh://git@gitlab.espressif.cn:27227/igrokhotkov/newlib_xtensa-2.2.0.git
    ignore = dirty


The file include/newlib.h contains:
#define _NEWLIB_VERSION "2.2.0"

The only file with xtensa in the path is 
./include/xtensa/config/core-isa.h which is included from include/sys/config.h

Otherwise few (12) files have rather minor xtensa specific code.
Comment 9 lekto 2021-08-17 13:50:25 UTC
I figured out how to install xtensa's newlib with crossdev: I edited sys-libs/newlib-9999 ebuild to clone right newlib repo and removed patch from ebuild. After that I run:
>crossdev --libc 9999 -s4 xtensa-esp32-elf
and it worked, but Arduino IDE gives me this error when I'm trying to use it:
>In file included from /home/lekto/Arduino/hardware/espressif/esp32/tools/sdk/esp32/include/freertos/include/freertos/portable.h:52,
>                 from /home/lekto/Arduino/hardware/espressif/esp32/tools/sdk/esp32/include/freertos/include/freertos/FreeRTOS.h:64,
>                 from /home/lekto/Arduino/hardware/espressif/esp32/cores/esp32/Arduino.h:33,
>                 from /tmp/arduino_build_153247/sketch/sketch_aug17a.ino.cpp:1:
>/home/lekto/Arduino/hardware/espressif/esp32/tools/sdk/esp32/include/freertos/port/xtensa/include/freertos/portmacro.h:329:15: error: expected constructor, destructor, or type conversion before ‘(’ token
>  329 | _Static_assert(portGET_ARGUMENT_COUNT() == 0, "portGET_ARGUMENT_COUNT() result does not match for 0 arguments");
>      |               ^
>/home/lekto/Arduino/hardware/espressif/esp32/tools/sdk/esp32/include/freertos/port/xtensa/include/freertos/portmacro.h:330:15: error: expected constructor, destructor, or type conversion before ‘(’ token
>  330 | _Static_assert(portGET_ARGUMENT_COUNT(1) == 1, "portGET_ARGUMENT_COUNT() result does not match for 1 argument");
>      |               ^
>exit status 1
Tested with gcc 8.5.0, 9.4.0, 10.3.0, 11.2.0 and I'm getting same error message.
Comment 10 SpanKY gentoo-dev 2021-10-27 09:43:20 UTC
crossdev's automatic handling of xtensa tuples is working as expected.  there is no Gentoo port to xtensa, so we have to try and extrapolate values.  whether xtensa is working in various packages is a matter for those packages.

binutils seems fine.  gcc too.

if newlib is deficient, then please take it up with the newlib folks (upstream).  if you want to point to a fork of newlib, write such an ebuild and use the --lpkg option.  based on the error, it does indeed look like a newlib problem:
> *** Newlib does not support CPU xtensa

i guess you could request that we carry the xtensa-specific patches for newlib, or ship a forked newlib-xtensa package, but i don't think there's any real appetite for that on the developer side.  if you wanted to volunteer to be a proxy maintainer for one, then maybe you could get that merged.