[J-core] Updated ghdl toolchain build script.

Rob Landley rob at landley.net
Sun Sep 27 07:11:53 UTC 2020


On 9/21/20 5:09 AM, Rob Landley wrote:
> I'm trying* to clean it up so the resulting binaries are portable and I can
> point you at a binary tarball and "license compliance source tarball"**, but
> it's being stroppy***.
...
> ** The problem is yosys and ghdl both want to dlopen() other packages so you
> can't statically link EITHER of them or you hit the old "the dynamically linked
> instance of malloc() maintains a heap stored in the pointer in the library, and
> the statically linked malloc() maintains a heap stored in the pointer statically
> linked into the binary, and the code here calls malloc() against one heap
> instance and free() against the other heap instance and now you have at BEST
> leaked memory and more likely either corrupted the receiving heap or thrown a
> stack trace and aborted" problem. And since half this crap is written in
> <strike>cobol</strike>ada it needs to use its own magic copy of gcc with ada
> support added, meaning I can't point it at one that'll link against musl instead
> of glibc and at least _mitigate_ that problem. Oh, and it won't use gnat-6 it
> insists on gnat-8 which devuan hasn't packaged, which is CRAPTACULAR to build
> from source, and which https://www.adacore.com/download only provides nightly
> snapshots of with NO HISTORY of previous versions (just a link to TONIGHT's and
> nothing else) but has horrible stupid like adding -2019 to library names that
> then get pulled into the resulting binary's dynamic link dependency list and
> CHANGE EVERY JANUARY. Ahem. Working on it...

So I need to make libghdl-1_0_dev.so statically link against libgnat (to avoid
version skew in the dereferenced library name) while dynamically linking against
everything else (to avoid heap splitting). I managed to make this happen by
hitting the ghdl build with a large rock, specifically:

--- a/yogh.sh
+++ b/yogh.sh
@@ -58,7 +58,7 @@ cd .. || exit 1

 cd ghdl &&
 ./configure --enable-libghdl --enable-synth --prefix="$PREFIX" &&
-make all install -j $(nproc)
+make all install -j $(nproc) LARGE_ROCK="-lgnat_pic -Wl,--as-needed"
 cd .. || exit 1

 cd ghdlsynth-beta &&

And then in ghdl:

--- a/Makefile.in
+++ b/Makefile.in
@@ -408,7 +408,7 @@ LIBGHDL_GRT_OBJS= pic/grt-cstdio.o
 $(libghdl_name): $(GRT_SRC_DEPS) $(LIBGHDL_GRT_OBJS) version.ads force
 #      Use -g for gnatlink so that the binder file is not removed.  We need
 #      it for libghdl.a
-       $(GNATMAKE) -I- -aI. -D pic -z libghdl -o $@ -gnat12 $(GNATFLAGS)
$(PIC_FLAGS) $(LIBGHDL_INCFLAGS) -bargs -shared -Llibghdl_ -largs -g -shared
$(SHLIB_FLAGS) $(LIBGHDL_GRT_OBJS)
+       $(GNATMAKE) -I- -aI. -D pic -z libghdl -o $@ -gnat12 $(GNATFLAGS)
$(PIC_FLAGS) $(LIBGHDL_INCFLAGS) -bargs -shared -Llibghdl_ -largs -g -shared
$(SHLIB_FLAGS) $(LIBGHDL_GRT_OBJS) $(LARGE_ROCK)
 #       On windows, gnatmake (via Osint.Executable_Name) always appends .exe
 #       Adjust.  (Other solution: use gnatmake for compilation and binding,
 #       then use gnatlink directly for linking).

The resulting library no longer needs libgnat-2019.so, which was the only thing
breaking a tarball extract into Jeff's test VM.

Rob

P.S. Yes, I looked at overriding each of the existing symbol names, and didn't
find a clean way to do it. They're used in multiple places, none of them are
blank or do += from inherited environment, and libgnat has ordering dependencies
in its arguments which I don't have the domain expertise to feel good about
doing anything but "stick it at the very end". Hence $LARGE_ROCK.


More information about the J-core mailing list