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

Make Newlib usable with Synopsys MetaWare toolchain #52

Merged
merged 4 commits into from
Nov 27, 2023

Conversation

abrodkin
Copy link
Member

@abrodkin abrodkin commented Nov 21, 2023

Synopsys MetaWare toolchain is a proprietary premium toolchain for ARC processors.
Now it's possible to build Newlib with MetaWare toolchain and use it as yet another standard C library for ARC cores.

To build it for ARC HS processor use the following commands, assuming MeratWare toolchain is in your PATH variable:

export AR_FOR_TARGET=llvm-arac
export AS_FOR_TARGET=asac
export CC_FOR_TARGET=ccac
export LD_FOR_TARGET=lldac
export RANLIB_FOR_TARGET=echo
export CFLAGS_FOR_TARGET="-av2hs -D__ARCHS__ -Dwint_t=int -DLONG_LONG_MAX=LLONG_MAX -DLONG_LONG_MIN=LLONG_MIN -DULONG_LONG_MAX=ULLONG_MAX -Hno_default_include -idirafter $METAWARE_ROOT/arc/inc"

mkdir build
cd build

../configure --target=arc --enable-multilib=no
make

".align" is supported by both GCC & MetaWare compiler for ARC,
yet implements the same semantics as ".balign" which only works with GCC.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
Copy link

@evgeniy-paltsev evgeniy-paltsev left a comment

Choose a reason for hiding this comment

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

coers -> cores

libgloss/arc/arc-timer.c Show resolved Hide resolved
@shahab-vahedi
Copy link
Member

shahab-vahedi commented Nov 23, 2023

@abrodkin please put the macro defs in this order:

#if defined (__GNUC__)
    ...
#elif defined (__CCAC__)
    ...
#else
    #error "Unexpected compiler"
#endif

libgloss/arc/crt0.S Outdated Show resolved Hide resolved
libgloss/arc/crt0.S Outdated Show resolved Hide resolved
@abrodkin
Copy link
Member Author

@abrodkin please put the macro defs in this order:

#if defined (__GNUC__)
    ...
#elif defined (__CCAC__)
    ...
#else
    #error "Unexpected compiler"
#endif

@shahab-vahedi that doesn't work that way because surprisingly ccac (i.e. clang) defines __GNUC__, see:

$ ccac -dM -E - < /dev/null | grep __GNUC__
#define __GNUC__ 4

So, will the following implementation be better than existing one?

#if defined (__CCAC__)
    ...
#elif defined (__GNUC__)
    ...
#else
    #error "Unexpected compiler"
#endif

@shahab-vahedi
Copy link
Member

shahab-vahedi commented Nov 24, 2023

#if defined (GNUC)
...
#elif defined (CCAC)
...
#else
#error "Unexpected compiler"
#endif

That is surprising indeed. I'll let @claziss make the final call on this. Till then, how about?

/* Our premium toolchain has a bipolar disroder. */
#if defined (__GNUC__) && !defined (__CCAC__)
    ...
#elif defined (__CCAC__)
    ...
#else
    #error "Unexpected compiler"
#endif

…oolchian happy

There's no semantic change, it's only to make the same code compilable with
MetaWare toolchian, which actually assumes "@x" as a full name, not omitting "@".

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
@abrodkin abrodkin force-pushed the abrodkin-2023.09-metaware branch from b3f0c52 to 4b965f2 Compare November 24, 2023 10:58
@abrodkin
Copy link
Member Author

@shahab-vahedi pushed a re-spin with the following changes:

  1. Fixed a commit msesage spello
  2. Switched to #if defined (xxx) semantics in compiler checks
  3. Removed @ from libgloss/arc/gcrt0.S & libgloss/arc64/crt0.S

@claziss
Copy link
Contributor

claziss commented Nov 24, 2023

#if defined (__CCAC__)
    ...
#elif defined (__GNUC__)
    ...
#else
    #error "Unexpected compiler"
#endif

@abrodkin Please comment why __CCAC__ is used first (i.e.,llvm is defining both macros). @shahab-vahedi I like your idea GNU first but the above is cleaner.

It makes it usable with standard symbol names defined in default linker scripts
of the MetaWare toolchain.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
@abrodkin abrodkin force-pushed the abrodkin-2023.09-metaware branch from 4b965f2 to 6248e51 Compare November 24, 2023 11:49
@abrodkin
Copy link
Member Author

@claziss done now. @BrunoASMauricio could you please run some testing on both ARC & ARC64 for this branch and if all is good, we may merge it, though not in arc-2023.09 as we're done with that, but I guess arc-2024.03 or something like that.

@shahab-vahedi
Copy link
Member

Looks good to me with one caveat.

ARC proprietary MetaWare ccac compiler uses its own built-ins, and so
we need to respect them.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
@abrodkin abrodkin force-pushed the abrodkin-2023.09-metaware branch from 6248e51 to cc43b66 Compare November 24, 2023 14:52
@abrodkin
Copy link
Member Author

#error "Unexpected compiler"

Done now.

@shahab-vahedi
Copy link
Member

Thank you @abrodkin for all the reworks.

@BrunoASMauricio
Copy link
Contributor

@abrodkin newlib and GCC baremetal tests don't show regression with these changes

@shahab-vahedi shahab-vahedi merged commit b8377b4 into arc-2023.09 Nov 27, 2023
2 checks passed
@shahab-vahedi shahab-vahedi deleted the abrodkin-2023.09-metaware branch November 27, 2023 15:19
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

Successfully merging this pull request may close these issues.

5 participants