Compile libgnat to a single LLVM bitcode file - ada

How can I compile libgnat to a single LLVM bitcode file? The latest dragonegg release is very old, so I provide a dockerfile to make testing more easy. My end goal is to run Ada in LLVM IR bitcode interpreters.
Dockerfile for the latest official dragonegg release
FROM ubuntu:trusty
COPY . /usr/src/workdir
WORKDIR /usr/src/workdir
RUN apt-get update \
&& apt-get -y install build-essential gnat-4.6 libgmp-dev libmpfr-dev libmpc-dev libz-dev gcc-4.6-plugin-dev
# libz-dev for ld when compiling dragonegg 3.3
# gcc-4.6-plugin-dev needed when compiling dragonegg 3.3
RUN tar -xzf gcc-4.6.4.tar.gz \
&& cd gcc-4.6.4 \
&& mkdir build \
&& cd build \
&& CC=gcc-4.6 ../configure --disable-multilib --enable-languages=ada,c,c++ --prefix=/opt/gcc-4.6.4 \
&& make -j4 \
&& make install
RUN tar -xzf clang+llvm-3.3-amd64-Ubuntu-12.04.2.tar.gz \
&& mv clang+llvm-3.3-amd64-Ubuntu-12.04.2 /opt/llvm-3.3
ENV PATH="/opt/llvm-3.3/bin:/opt/gcc-4.6.4/bin:${PATH}"
RUN tar -xzf dragonegg-3.3.src.tar.gz \
&& mv dragonegg-3.3.src dragonegg-3.3 \
&& cd dragonegg-3.3 \
&& GCC=/opt/gcc-4.6.4/bin/gcc make \
&& cp dragonegg.so /opt/dragonegg.so
download gcc-4.6.4.tar.gz
download clang+llvm-3.3-amd64-Ubuntu-12.04.2.tar.gz
download dragonegg-3.3.src.tar.gz
hello.adb
with Ada.Text_IO;
procedure Hello is
begin
Ada.Text_IO.Put_Line("Hello world from Ada (dragonegg)!");
end Hello;
Run gcc hello.adb -S -O1 -o hello.ll -fplugin=/opt/dragonegg.so -fplugin-arg-dragonegg-emit-ir to compile the hello.adb file. When I try to build the binary with llc -filetype=obj hello.ll and gcc hello.o, I get the following error:
/usr/lib/x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
hello.o: In function `_ada_hello':
hello.ll:(.text+0xb): undefined reference to `ada__text_io__put_line__2'
collect2: ld returned 1 exit status
The error message indicates that the Ada runtime library is missing. Currently, I have no idea, how I can compile the libgnat to a single LLVM bitcode file, so I can link it with the program.

Why are you using DragonEgg? That's well and truly dead! See https://github.com/AdaCore/gnat-llvm instead.

Related

Yocto toolchain installation with qscxmlc support

Hej Folks.
I try to implement a yocto and QT5 based project for a variscite board with QtSCXML support. I got everything run on QtCreator for my Hostmachine (Ubuntu 64-bit, 18.04), so I know my project has to be kinda right. For the yocto part, I used the installtion guide by variscite itself (Ref_1 and Ref_2). As targetmachine I use the VAR-SOM-6UL.
So my toolchain building process is the following:
$ sudo apt-get install gawk wget git diffstat unzip texinfo gcc-multilib \
build-essential chrpath socat cpio python python3 python3-pip python3-pexpect \
xz-utils debianutils iputils-ping libsdl1.2-dev xterm
$ sudo apt-get install autoconf libtool libglib2.0-dev libarchive-dev python-git \
sed cvs subversion coreutils texi2html docbook-utils python-pysqlite2 \
help2man make gcc g++ desktop-file-utils libgl1-mesa-dev libglu1-mesa-dev \
mercurial automake groff curl lzop asciidoc u-boot-tools dos2unix mtd-utils pv \
libncurses5 libncurses5-dev libncursesw5-dev libelf-dev zlib1g-dev bc rename
$ mkdir ~/bin (this step may not be needed if the bin folder already exists)
$ curl https://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
$ chmod a+x ~/bin/repo
$ export PATH=~/bin:$PATH
$ mkdir ~/var-fslc-yocto && cd ~/var-fslc-yocto
$ repo init -u https://github.com/varigit/variscite-bsp-platform.git -b dunfell
$ repo sync -j$(nproc)
$ MACHINE=imx6ul-var-dart DISTRO=fslc-x11 . setup-environment build_x11
Now I change the local.conf file in ~/var-fslc-yocto/build_x11/conf/. As default the connectivity check fails, so a diffrent url is deposited. The virtualization is only activated to suppress warning messages. To "include" the qtscxml, its append to the IMAGE as the nativesdk-qtscxml is append for the host toolchain.
But see for yourself:
MACHINE ??= 'imx6ul-var-dart'
DISTRO ?= 'fslc-x11'
PACKAGE_CLASSES ?= 'package_rpm'
EXTRA_IMAGE_FEATURES ?= "debug-tweaks"
USER_CLASSES ?= "buildstats image-mklibs image-prelink"
PATCHRESOLVE = "noop"
BB_DISKMON_DIRS ??= "\
STOPTASKS,${TMPDIR},1G,100K \
STOPTASKS,${DL_DIR},1G,100K \
STOPTASKS,${SSTATE_DIR},1G,100K \
STOPTASKS,/tmp,100M,100K \
ABORT,${TMPDIR},100M,1K \
ABORT,${DL_DIR},100M,1K \
ABORT,${SSTATE_DIR},100M,1K \
ABORT,/tmp,10M,1K"
PACKAGECONFIG_append_pn-qemu-system-native = " sdl"
CONF_VERSION = "1"
DL_DIR ?= "${BSPDIR}/downloads/"
ACCEPT_FSL_EULA = "1"
#check connectivity using google
CONNECTIVITY_CHECK_URIS = "https://www.google.com/"
#enable virtualization to disable warning
DISTRO_FEATURES_append = " virtualization"
#image extra
EXTRA_IMAGE_FEATURES = " \
qtcreator-debug \
ssh-server-openssh \
debug-tweaks \
tools-debug \
"
#use systemd
DISTRO_FEATURES_append = " systemd"
DISTRO_FEATURES_BACKFILL_CONSIDERED_append = " sysvinit"
VIRTUAL-RUNTIME_init_manager = "systemd"
VIRTUAL-RUNTIME_initscripts = ""
IMX_DEFAULT_DISTRO_FEATURES_append = " systemd"
#image install
IMAGE_INSTALL_append = " \
qtscxml \
"
#toolchain host
TOOLCHAIN_HOST_TASK += "qtscxml \
nativesdk-qtscxml \
"
Now comes the happy building part and the Problems beginn!
I will just type what i'm doing:
$ bitbake -c populate_sdk fsl-image-qt5
$ . ~/var-fslc-yocto/build_x11/tmp/deploy/sdk/fslc-x11-glibc-x86_64-fsl-image-qt5-cortexa7t2hf-neon-imx6ul-var-dart-toolchain-3.1.sh
$ . /opt/fslc-x11/3.1/environment-setup-cortexa7t2hf-neon-fslc-linux-gnueabi
$ cd ~/TestProject
$ mkdir build
$ qmake -makefile -o build/MakeFile test.pro
$ make -C build/
And now the error message i receive ..
make: Entering directory '/home/yocto/TestProject/build'
make: *** No rule to make target '/opt/fslc-x11/3.1/sysroots/x86_64-fslcsdk-linux/usr/bin/qscxmlc', needed by 'custom_statemachine.h'. Stop.
make: Leaving directory '/home/yocto/TestProject/build'
(custom_statemachine.h isn't written by me, I only generated custom_statemachine.scxml)
Do i missed something? Why is Qts SCXML Compiler qscxmlc missing?
Thanks to everyone how read this far, thanks for every suggestions and sorry for every grammatical mistake.

Static build of Nginx

I am preparing a Docker image that intends to use a static build of Nginx
RUN set -ex \
&& wget -qO- github.com/nginx/nginx/archive/"$NGINX_HASH".tar.gz | tar zx --strip-components=1 \
&& ./auto/configure --without-http_rewrite_module --without-http_gzip_module \
&& make CFLAGS="-O2 -s" LDFLAGS="-static" -j$(nproc) \
&& ldd ./objs/nginx
Unfortunately, even with the flags -static it seems to be linked against musl
ldd ./objs/nginx
/lib/ld-musl-x86_64.so.1 (0x7fcce5ebe000)
libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x7fcce5ebe000)
What do I need to do to link statically?
Solved with
RUN ./auto/configure --without-http_rewrite_module --without-http_gzip_module --with-cc-opt="-O2" --with-ld-opt="-s -static"

Issue in Copying DLL from Common gitrepo to the application repo to make application run

I have a Dotnet application where my repo structure is as below
FolderA
SubfolderA
-Contains DLL file
FolderB
SubfolderA
-Contains application code and Dockerfile
SubfolderB
-Contains application code and Dockerfile
SubfolderC
-Contains application code and Dockerfile
When i build the Dockerfile in subfolder A, I want the Dockerfile to call or copy the DLL from the Folder A and run the application.
I have tried adding the following in the below Dockerfile
RUN ls -l /src
RUN cp '../../FolderA/subfolderA/OPCUAServer.dll' 'FolderB/subfolderA/'
The above command i added in the first phase of the image , but seems not working
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-focal AS build
# passing the root and nuget TLS certificates for the package to download
COPY ./CIdependencies/rootca.cer /etc/ssl/certs/rootca.cer
COPY ./CIdependencies/nuget.cer /etc/ssl/certs/nuget.cer
WORKDIR /etc/ssl/certs
RUN openssl x509 -inform DER -in nuget.cer -out nuget.crt \
&& openssl x509 -inform PEM -in rootca.cer -out rootca.crt \
&& update-ca-certificates \
&& echo $PWD
WORKDIR /src
EXPOSE 62501
COPY ["OPCUAServer.csproj", ""]
RUN dotnet restore "./OPCUAServer.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "OPCUAServer.csproj" -c Release -o /app/build \
&& dotnet publish "OPCUAServer.csproj" -c Release -o /app/publish
FROM ubuntu:20.04
ARG GIT_COMMIT
ARG DS_VERSION=0.0.0.0
# passing the root certificates for the package to download
COPY ./CIdependencies/zscaler-rootca.cer /etc/ssl/certs/rootca.cer
LABEL Name=OPCUAServer Version=$DS_VERSION git_commit=$GIT_COMMIT
#runtime-deps and runtime
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
&& rm -rf /var/lib/apt/lists/*
ENV \
# Configure web servers to bind to port 80 when present
ASPNETCORE_URLS=http://+:8079 \
# Enable detection of running in a container
DOTNET_RUNNING_IN_CONTAINER=true
# Install .NET Core and ASPdotnet.3.1. focal
RUN dotnet_version=3.1.18 \
# passing the root certificates for the package to download
&& curl -fsl --cacert /etc/ssl/certs/rootca.cer --output dotnet.tar.gz https://dotnetcli.azureedge.net/dotnet/Runtime/$dotnet_version/dotnet-runtime-$dotnet_version-linux-x64.tar.gz \
&& dotnet_sha512='6f06dbc4625fa8a0e64ffb9269b5f657e369fd28e7f27bfd05d4f422c6aa95847b5089d70760024bdf1100990dbbffce220a' \
&& echo "$dotnet_sha512 dotnet.tar.gz" | sha512sum -c - \
&& mkdir -p /usr/share/dotnet \
&& tar -ozxf dotnet.tar.gz -C /usr/share/dotnet \
&& rm dotnet.tar.gz \
&& ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet \
&& aspnetcore_version=3.1.18 \
&& curl -fsl --cacert /etc/ssl/certs/zscaler-rootca.cer --output aspnetcore.tar.gz https://dotnetcli.azureedge.net/dotnet/aspnetcore/Runtime/$aspnetcore_version/aspnetcore-runtime-$aspnetcore_version-linux-x64.tar.gz \
&& aspnetcore_sha512='be29a7611941d9b20d5d3ece64d3ce3c2342ba24bf0382eed3625713ce89957fa15671403af16ccb588397fc0b27e7f028952213e08db6' \
&& echo "$aspnetcore_sha512 aspnetcore.tar.gz" | sha512sum -c - \
&& tar -ozxf aspnetcore.tar.gz -C /usr/share/dotnet ./shared/Microsoft.AspNetCore.App \
&& rm aspnetcore.tar.gz
# Create a user, group and providing permission to access the built files
WORKDIR /app
RUN groupadd -r opc && useradd --no-log-init -r -g opc opc
USER opc
COPY --from=build --chown=opc:opc /app/publish .
ENTRYPOINT ["dotnet", "OPCUAServer.dll"]

Compiling a .Net Core Console App with Npgsql and CoreRT

I'm trying to compile a .net core console application into native executable (linux-x64) on an ubuntu 18.04 docker container, using both coreRT and Npgsql. I'm currently using docker-compose to set up the DB and application containers.
docker-compose.yml
version: '3'
services:
database:
image: postgres:10
environment:
- POSTGRES_USER=dbuser
- POSTGRES_PASSWORD=dbpassword
- POSTGRES_DB=dbsample
ports:
- 5432:5432
tmpfs:
- /var/lib/postgresql/data:rw,noexec,nosuid,size=400m
volumes:
- ./db-init:/docker-entrypoint-initdb.d
prototype:
build: .
depends_on:
- database
links:
- database:database
Dockerfile
FROM ubuntu:18.04
RUN apt-get update \
&& apt-get install -y \
apt-transport-https \
build-essential \
clang \
cmake \
curl \
git-core \
gpg \
libbz2-dev \
libkrb5-dev \
libncurses5-dev \
libncursesw5-dev \
libreadline-dev \
libsqlite3-dev \
libssl-dev \
llvm \
make \
parallel \
wget \
zlib1g-dev
RUN wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.asc.gpg \
&& mv microsoft.asc.gpg /etc/apt/trusted.gpg.d/ \
&& wget -q https://packages.microsoft.com/config/ubuntu/18.04/prod.list \
&& mv prod.list /etc/apt/sources.list.d/microsoft-prod.list \
&& chown root:root /etc/apt/trusted.gpg.d/microsoft.asc.gpg \
&& chown root:root /etc/apt/sources.list.d/microsoft-prod.list \
&& apt-get update \
&& apt-get install -y dotnet-sdk-2.2
ENV CppCompilerAndLinker=clang-6.0
ENV DOTNET_CLI_TELEMETRY_OPTOUT=true
WORKDIR /home/app
COPY ./HelloWorld.fsproj /home/app
COPY ./nuget.config /home/app
RUN dotnet restore
COPY ./ /home/app
RUN dotnet publish -r linux-x64 -c Release -v detailed -o outside
CMD ./outside/HelloWorld
When It gets to compile it (dotnet publish -r linux-x64 -c Release -v detailed -o outside), it enters infinite loop consuming all the memory avaiable for the container. Until it shows this error:
Task "Exec"
"/root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/1.0.0-alpha-27919-02/tools/ilc" #"obj/Release/netcoreapp2.2/linux-x64/native/HelloWorld.ilc.rsp"
Killed
1:7>/root/.nuget/packages/microsoft.dotnet.ilcompiler/1.0.0-alpha-27919-02/build/Microsoft.NETCore.Native.targets(249,5): error MSB3073: The command ""/root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/1.0.0-alpha-27919-02/tools/ilc" #"obj/Release/netcoreapp2.2/linux-x64/native/HelloWorld.ilc.rsp"" exited with code 137. [/home/app/HelloWorld.fsproj]
Done executing task "Exec" -- FAILED.
1:7>Done building target "IlcCompile" in project "HelloWorld.fsproj" -- FAILED.
1:7>Done Building Project "/home/app/HelloWorld.fsproj" (Publish target(s)) -- FAILED.
It seems to be somehow related with the usage of generics and reflections in F#. I've looked in both Npgsql and coreRT repos and couldn't find someone close to get them both working. Have anyone faced this problem? Or managed to use Npgsql and coreRT?

grunt-cli doesn't work with docker volume mounted, fine without

I set up an angular development environment using the following Dockerfile (don't try to build this unless you're really enthusiastic, it takes an age).
FROM ubuntu:14.04
# build environment
RUN ["apt-get", "update"]
RUN ["apt-get", "install", "-y", "nodejs", "npm", "git"]
RUN ["ln", "-s", "/usr/bin/nodejs", "/usr/bin/node"]
RUN ["npm", "install", "-g", "yo"]
RUN ["npm", "install", "-g", "bower"]
RUN ["npm", "install", "-g", "grunt-cli"]
WORKDIR /home/angular
ADD ./package.json /home/angular/package.json
ADD ./bower.json /home/angular/bower.json
ADD ./dist /home/angular/dist
RUN ["npm", "install"]
RUN ["bower", "install", "--allow-root"]
# sass depedencies
ENV RUBY_MAJOR 2.2
ENV RUBY_VERSION 2.2.2
ENV RUBY_DOWNLOAD_SHA256 5ffc0f317e429e6b29d4a98ac521c3ce65481bfd22a8cf845fa02a7b113d9b44
# some of ruby's build scripts are written in ruby
# we purge this later to make sure our final image uses what we just built
RUN ["apt-get", "install", "-y", "curl"]
RUN apt-get update \
&& apt-get install -y autoconf bison libgdbm-dev ruby \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir -p /usr/src/ruby \
&& curl -fSL -o ruby.tar.gz "http://cache.ruby-lang.org/pub/ruby/$RUBY_MAJOR/ruby-$RUBY_VERSION.tar.gz" \
&& echo "$RUBY_DOWNLOAD_SHA256 *ruby.tar.gz" | sha256sum -c - \
&& tar -xzf ruby.tar.gz -C /usr/src/ruby --strip-components=1 \
&& rm ruby.tar.gz \
&& cd /usr/src/ruby \
&& autoconf \
&& ./configure --disable-install-doc \
&& make -j"$(nproc)" \
&& make install \
&& apt-get purge -y --auto-remove bison libgdbm-dev ruby \
&& rm -r /usr/src/ruby
# skip installing gem documentation
RUN echo 'gem: --no-rdoc --no-ri' >> "$HOME/.gemrc"
# install things globally, for great justice
ENV GEM_HOME /usr/local/bundle
ENV PATH $GEM_HOME/bin:$PATH
ENV BUNDLER_VERSION 1.10.5
RUN gem install bundler --version "$BUNDLER_VERSION" \
&& bundle config --global path "$GEM_HOME" \
&& bundle config --global bin "$GEM_HOME/bin"
# don't create ".bundle" in all our apps
ENV BUNDLE_APP_CONFIG $GEM_HOME
RUN gem install compass
VOLUME ["/home/me/code/correspondence/client/dist"]
ADD ./ /home/angular
If I run this with:
sudo docker run -it me/angular /bin/bash
I can use grunt build with no problems. Since I haven't attached a volume to dist that build is no use to other containers such as the webserver. But running:
sudo docker run -itv /home/me/code/correspondence/client/dist:/home/angular me/angular /bin/bash
results in the grunt build command no longer being usable in the container:
grunt-cli: The grunt command line interface. (v0.1.13)
Fatal error: Unable to find local grunt.
If you're seeing this message, either a Gruntfile wasn't found or grunt
hasn't been installed locally to your project. For more information about
installing and configuring grunt, please see the Getting Started guide:
http://gruntjs.com/getting-started
The only difference is adding the volume. How does adding the volume result in this different behaviour?
I suppose that's because you have placed some files to /home/angular in image and when you're mounting your volume to the same path (/home/angular), your volume hides original files.
Quote from documentation:
Note: If the path /opt/webapp already exists inside the container’s
image, its contents will be replaced by the contents of /src/webapp on
the host to stay consistent with the expected behavior of mount
Try to mount volume to another directory, /home/angular/dist/client, for instance.

Resources