Building chipKIT compiler on Ubuntu 14.04 64-bit

Work prioritization by the chipKIT core development team
jdeguire
Posts: 10
Joined: Wed Mar 23, 2016 7:39 pm

Building chipKIT compiler on Ubuntu 14.04 64-bit

Post by jdeguire » Tue Mar 29, 2016 4:40 pm

Apologies if this is the wrong section, but this appears to be the one most related to building source stuff.

Anyway, I've been on a quest to build the chipKIT compiler from https://github.com/chipKIT32/chipKIT-cxx using the script from https://github.com/chipKIT32/chipKIT-cxx-build. I'm doing this on Ubuntu 14.04 LTS 64-bit (in VirtualBox). The README that is provided with the script states that it was meant for OS X 10.6 or 10.7, however.

Unfortunately, I am running into a bit of trouble at the moment. On the plus side that gives me an opportunity to at least share what I've done so far in case anyone else wants to try building on Ubuntu. :)

Prerequisites
The README provides the software packages needed for OS X, but things are a bit different here. Here are the packages you need; get them either using the apt-get install command or via the Ubuntu Software Center. Remember that these are for Ubuntu 14.04 64-bit.
  • build-essential
  • mingw32
  • gcc-multilib
  • g++-multilib
  • texinfo
  • flex
  • bison
  • libncurses5
  • libncurses5-dev
  • gcc-arm-linux-gnueabi
  • g++-arm-linux-gnueabi
Edit: Added g++-multilib package.
Edit 2016 Mar 31: Added ARM cross-compiler packages.

The other packages listed (curl, rsync, etc.) should already be installed. The "growl" and "growl-notify" packages are not needed as they are specific to OS X. You'll still get nice notifications in Ubuntu.

NOTE: The "build-essential" package will bring in GCC 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.1). This is different from what the script's README wanted (GCC 4.2), but ought to be OK since the newest chipKIT compiler is based on GCC 4.8.3.

You also need Texinfo, but the version that the Ubuntu package repository provides is too new and will cause all sorts of errors with GCC 4.8 docs. You can tell GCC to not build its docs, but unfortunately the script barfs on the warnings the GCC instead outputs. Instead, you need to build and install an older Texinfo from source using the instructions provided at http://askubuntu.com/questions/491184/texinfo-downgrade.

Script Modifications
I grabbed the latest script from GitHub and made a few mods to make it run. I have attached the modified script to this message.

1. The first modification is minor. Search for the comment "#Process the arguments" to see a case structure to handle command-line options. You'll see a reference to a function (or whatever they call those in Bash-speak) called "show_usage". However, that function is defined after it is referenced and so will not work. Find the "show_usage()" function and move it above the case structure.

2. To make the other change, search for the comment "#Check out the source code". Scroll down a bit and you'll notice that the portion of the script to grab the source of the actual compiler is commented out! Uncomment that section and then change the GIT_CHIPKIT_CXX_REPO variable to https://api.github.com/repos/chipKIT32/ ... all/master.

Edit 2016 Mar 31: Added new mods to script

3. The script needs to be modified if you are running on a 64-bit Linux to force the chipKIT compiler to be built in 32-bit mode. Search for "xDarwin-image" to find an if-statement. This checks if the script is running on OS X. Scroll down a bit to find the corresponding else-clause and add the following inside of it:

Code: Select all

    # We need to force a 32-bit build if we're on 64-bit Linux
    if [ `getconf LONG_BIT` = "64" ]
    then
        if [ "x$SKIPNATIVE" == "x" ] ; then
            COMPATIBILITY_FLAGS="-m32 -march=i686"
            export CXX_FOR_BUILD="g++ $COMPATIBILITY_FLAGS"
            export CC_FOR_BUILD="gcc $COMPATIBILITY_FLAGS"
            export CC="gcc $COMPATIBILITY_FLAGS"
            export CPP="cpp $COMPATIBILITY_FLAGS"
            export CXX="g++ $COMPATIBILITY_FLAGS"
            export LD="gcc $COMPATIBILITY_FLAGS"
            export AR="ar"
        fi  # SKIPNATIVE
    fi
You could probably change the "i386" in there to something more modern if you're just building for yourself.

4. Ubuntu 14.04 has a different name for the ARM cross-compiler than OS X does, it seems, so the script needs to be updated to figure out which compiler prefix (the "blahblah" in "blahblah-gcc"). Search for "unset ARMLINUX32_HOST_PREFIX" near the top of the script. Replace that line and the following assignment with the following code:

Code: Select all

# Figure out which ARM cross compiler we have. Candidates are:
# arm-linux-gnueabi-gcc           (Ubuntu)
# arm-none-linux-gnueabi-gcc      (OS X)
if [ "x$ARMLINUX32_HOST_PREFIX" == "x" ]; then
 WHICH_ARM_GCC=`which arm-none-linux-gnueabi-gcc`
 if [ "x$WHICH_ARM_GCC" != "x" ] ; then
  ARMLINUX32_HOST_PREFIX=arm-none-linux-gnueabi
 else
  ARMLINUX32_HOST_PREFIX=arm-linux-gnueabi
 fi
 unset WHICH_ARM_GCC
fi

Running the Script
At this point you should be able to run the script. If you've already run the script once and thus have already checked out the code, you can pass the "-N" command-line option to stop the script from re-downloading the source. In the future, I may try adding an option to only download the sources for archival purposes.

...Aaannnnd I'm Stuck
Edit 2016 Mar 31: This is no longer true! I am no longer stuck! :D
So it is at this point I am stuck in the build. What appears to be happening is that the chipKIT build (pic32-gcc) is segfauting while trying to build Newlib. I'm not sure why this is happening, but I wonder if it is because I am building on a 64-bit OS and thus building a 64-bit version of the compiler. I notice that the script appears to force a 32-bit build when on OS X, so hopefully I can leverage that code to make it work. I'll update this thread with my progress, but I'll attach my build log in case one of you guys has run into this before.

On another note, is is normal for the build to emit so many warnings? Ubuntu's GCC (4.8.4) seems to emit a whole lot of warnings when building the chipKIT compiler, mainly about local variables shadowing global ones of the same name.


Edit 2016 Mar 31: This post used to have a modified build script and a log showing where I was originally stuck building. I have removed both of those. A later post has a new build script that you should use instead.
Last edited by jdeguire on Fri Apr 01, 2016 10:05 pm, edited 3 times in total.

User avatar
majenko
Site Admin
Posts: 2164
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK
Contact:

Re: Building chipKIT compiler on Ubuntu 14.04 64-bit

Post by majenko » Tue Mar 29, 2016 6:05 pm

I think building on 64-bit will be doomed to failure even if you get it to complete.

I have requested a 64-bit version of the compiler from the maintainers, but they claim that it would mean making changes to the internals to get it to work on 64-bit.

Out of interest, why exactly are you attempting to compile it yourself when there are binaries available?
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

jdeguire
Posts: 10
Joined: Wed Mar 23, 2016 7:39 pm

Re: Building chipKIT compiler on Ubuntu 14.04 64-bit

Post by jdeguire » Wed Mar 30, 2016 1:08 pm

Hi majenko,

The pre-built distributions appear to not come with the GNU C++ libraries, which would be nice to have. That, and it is a good excuse for me to get back into Linux and re-learn all that I've forgotten long ago! :mrgreen:

You are right that the 64-bit build was the issue. I was able to modify the script to force a 32-bit build and it got much further along. Right now, it is failing to build the ARM->MIPS Canadian cross compiler, which I assume is for the chipKIT Pi stuff. I didn't install any ARM tools, so I wouldn't expect it to build just yet. I don't need the ARM compiler at all, but I'll get it building and update this thread so that others who need it can use it.

I'll clean up my modified script a bit and post the updated version when I get a bit further along.

jdeguire
Posts: 10
Joined: Wed Mar 23, 2016 7:39 pm

Re: Building chipKIT compiler on Ubuntu 14.04 64-bit

Post by jdeguire » Thu Mar 31, 2016 2:47 pm

SUCCESS!! :D

I was able to build everything, including the ARM->MIPS compiler, on Ubuntu 14.04. Attached to this post is the updated script needed to do that. I'll edit the first post with the extra prerequisites needed for it as well as the additional modifications to the script I need.

Now to see if I can build it with full libstdc++ support! Hopefully, simply changing SUPPORT_HOSTED_LIBSTDCXX at the very top of the file to an empty string ("") will do it.
Attachments
chipKIT-cxx-build.sh.txt
Updated build script; remove ".txt".
(89.89 KiB) Downloaded 30 times

User avatar
majenko
Site Admin
Posts: 2164
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK
Contact:

Re: Building chipKIT compiler on Ubuntu 14.04 64-bit

Post by majenko » Thu Mar 31, 2016 4:07 pm

That's great work! If you should get it working with the gcc c++ library I may have to think about providing it as an optional alternative to the stock compiler on UECIDE...

Sent from my SM-T555 using Tapatalk
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

jdeguire
Posts: 10
Joined: Wed Mar 23, 2016 7:39 pm

Re: Building chipKIT compiler on Ubuntu 14.04 64-bit

Post by jdeguire » Thu Mar 31, 2016 5:00 pm

Another script update:

This version adds the "-S" option, which will allow you to download the source code without building it. This can be used if you want to keep a local archive of the code. Do not use this with the "-N" option, which will try to build without downloading the source.
Attachments
chipKIT-cxx-build.sh.txt
Adds "-S" option; remove ".txt"
(90.3 KiB) Downloaded 20 times

jdeguire
Posts: 10
Joined: Wed Mar 23, 2016 7:39 pm

Re: Building chipKIT compiler on Ubuntu 14.04 64-bit

Post by jdeguire » Fri Apr 01, 2016 7:49 pm

majenko wrote:That's great work! If you should get it working with the gcc c++ library I may have to think about providing it as an optional alternative to the stock compiler on UECIDE...
At the top of the script, change the variable SUPPORT_HOSTED_LIBSTDCXX to an empty string (""). Then, in NEWLIB_CONFIGURE_FLAGS and GCC_CONFIGURE_FLAGS right below that, remove the "--disable-hosted-libstdcxx" option. That appears to cause the script to build the full C++ library.

Note that I haven't yet used the compiler to make sure it actually works; I'm still working through building it.

Also, search for "-march=i386" and change that to "-march=i686".

jdeguire
Posts: 10
Joined: Wed Mar 23, 2016 7:39 pm

Re: Building chipKIT compiler on Ubuntu 14.04 64-bit

Post by jdeguire » Tue Apr 05, 2016 4:20 pm

Attached is yet another script update!

This update is fairly substantial, so instead of posting all of the details of what I did I'll just describe the new features. You can use a diff tool such as Beyond Compare, WinMerge, or Meld (Ubuntu) to see what I've changed.
  • Add "-A" option to disable building of the ARM->MIPS cross-compiler.
  • Add "-G" option to enable building of the Graphite loop optimization framework. This enables certain optimizations in GCC that can re-arrange loops and auto-parallelize them. This may be of limited use on the PIC32, but the option is there for anyone who wants it.
  • Add "-X" option to enable building the full libstdc++ library to get full C++ support. Note that this has not yet been tested and so further modifications may be needed to make C++ actually work.
  • In order for GCC to properly build Graphite, I had to update the script to download and build a stand-alone version of the ISL library. The download comes from the GNU FTP server. The CLooG library comes with a version of ISL, but a bug prevents GCC from accepting it as a usable version. NOTE: If you want the sources only, use the "-G" and "-S" options together.
  • For 64-bit Linux, change the build architecture from "i386" to "i686".
  • The sources contain PIC32 device info files that need to be included with the compiler images when they are built; however, the pic32-part-support Makefile did not provide a means to add them. The script will add a build target to "pic32-part-support/Makefile" called "install-devinfo" that will install the device info files to the proper places (I copied the XC32 layout for this) and then make that target when installing the headers.
  • Update USE_PPL and USE_CLOOG variables as needed when building those libraries for each architecture (native, Linux32, Win32, ARM-Linux).
  • Minor updates to echoed output that better points out which architecture is currently being worked on.
Attachments
chipKIT-cxx-build.sh.txt
Updated build script; remove ".txt"
(96.32 KiB) Downloaded 23 times

jdeguire
Posts: 10
Joined: Wed Mar 23, 2016 7:39 pm

Re: Building chipKIT compiler on Ubuntu 14.04 64-bit

Post by jdeguire » Tue Apr 05, 2016 7:09 pm

With previous mods of the script, I was pulling the toolchain source from https://github.com/chipKIT32/chipKIT-cxx as I thought that was the "proper" location. It does appear that future builds will come from there, but the current binary release provided with the latest chipKIT Core is built from the "dev_src48x" branch at https://github.com/mariusgeanta/chipKIT ... dev_src48x.

This version of the script is exactly the same as the previous except that it reverts back to the original script's behavior of pulling the toolchain source from the "mariusgeanta" fork. This will allow the build to more closely match the binary release. To switch between branches, simply uncomment one of the following lines in the script and comment out the other:

Code: Select all

#GIT_CHIPKIT_CXX_REPO=https://api.github.com/repos/chipKIT32/chipKIT-cxx/tarball/master
GIT_CHIPKIT_CXX_REPO=$GIT_ROOT/chipKIT-cxx/tarball/dev_src48x
Attachments
chipKIT-cxx-build.sh.txt
(96.38 KiB) Downloaded 24 times

jdeguire
Posts: 10
Joined: Wed Mar 23, 2016 7:39 pm

Re: Building chipKIT compiler on Ubuntu 14.04 64-bit

Post by jdeguire » Wed May 11, 2016 11:31 pm

One more update. Like previous scripts, the toolchains built from this haven't yet gotten much runtime so keep in mind that you use these at your own risk.

Since last time, I've also learned that you must explicitly pass "-lstdc++" when linking if you want to use stuff from the C++ library (assuming you enabled it). If you're getting linker errors about undefined references to C++ symbols, give that a shot.
  • Attempted to clean up the indentation and many of the commands the script issues to make it easier to modify in the future. Many of the commands redefined variables like "CFLAGS_FOR_TARGET", "CXXFLAGS_FOR_TARGET", and so on, but redefined them using the same values over and over again. Where possible, commands now reference common variables at the top of the file such that changing those common variables should apply the changes to all relevant commands, thus helping to ensure all versions of the toolchain are built with the same options.
  • Add -E option to disable the SJLJ exception handling model, which should use the DWARF2 exception handling model instead. I have not yet tried out this option, so DWARF2 exceptions could be horribly broken for all I know.
  • Remove configuration options that disabled C++ exceptions and RTTI, so those should now be usable when building C++ code.
  • Remove all uses of the PPL library as GCC 4.8 no longer requires it. This matters only if you are building in Graphite optimizations.
  • Copy library and processor-specfic file sources from the pic32-part-support/ directory into each install image as it can come in handy. This can be disabled to give you a smaller install image by opening the script and setting SKIPLIBSOURCES to "yes".
If you find an issue, consider attempting a fix and uploading your successes here. That'll help others who may find it useful.
Attachments
chipKIT-cxx-build.sh.txt
(78.61 KiB) Downloaded 13 times

Post Reply