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

Add iputils static PIE build #87

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions iputils/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/iputils-*
/*.tar.gz
65 changes: 65 additions & 0 deletions iputils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# iputils

Build the [iputils](https://github.com/iputils/iputils/) set of tools as static PIE ELF binaries running on Linux.

## Requirements

Make sure the following packages are installed:
* gcc >= 8 (required for the `-static-pie` linking option)
Comment on lines +7 to +8
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Make sure the following packages are installed:
* gcc >= 8 (required for the `-static-pie` linking option)
Make sure the following packages are installed:
* gcc >= 8 (required for the `-static-pie` linking option)

* autotools
* meson
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* meson
* meson
* xsltproc

* GNU Make

For Debian, run the command below to install all requirements:

```bash
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
```bash
```console

$ sudo apt install build-essential
export DEBIAN_FRONTEND="noninteractive"

apt update

apt install -y --no-install-recommends \
clang \
docbook-xsl-ns \
file \
gcc \
gettext \
iproute2 \
libcap-dev \
libidn2-0-dev \
libssl-dev \
make \
meson \
pkg-config \
xsltproc

```

## Building

The static PIE ELF file are located in the current directory.
If you want to rebuild them, run:

```bash
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
```bash
```console

$ ./build.sh
```

This script downloads, unpacks, patches, configures and builds the tools.

## Running

The resulting binaries can be used as is.
For example, you can ping an address by issuing the command:

```bash
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
```bash
```console

$ ./ping 1.1.1.1
```

## Issues

1. When running in KVM with LWIP you can't use RAW sockets because they're not
available by default. See this for more information:
https://github.com/unikraft/lib-lwip/pull/2
Comment on lines +60 to +62
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
1. When running in KVM with LWIP you can't use RAW sockets because they're not
available by default. See this for more information:
https://github.com/unikraft/lib-lwip/pull/2
1. When running in KVM with LWIP you can't use RAW sockets because they're not available by default.
See [this](https://github.com/unikraft/lib-lwip/pull/2) for more information.


2. There is a bug in LWIP where normal sockets (not RAW) that use ICMP protocol
are sent using UDP protocol instead. See https://github.com/unikraft/lib-lwip/issues/32
Comment on lines +64 to +65
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
2. There is a bug in LWIP where normal sockets (not RAW) that use ICMP protocol
are sent using UDP protocol instead. See https://github.com/unikraft/lib-lwip/issues/32
2. There is a bug in LWIP where normal sockets (not RAW) that use ICMP protocol are sent using UDP protocol instead.
See [issue `#32`](https://github.com/unikraft/lib-lwip/issues/32).

Binary file added iputils/arping
Binary file not shown.
33 changes: 33 additions & 0 deletions iputils/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash


BUILD_VERSION=20221126
# Clean up.
rm -fr iputils-*
rm -fr *.tar.gz

echo -n "Downloading iputils ... "
wget -O "${BUILD_VERSION}.tar.gz" -q https://github.com/iputils/iputils/archive/refs/tags/${BUILD_VERSION}.tar.gz
echo ""

echo -n "Unpacking iputils ... "
tar xzf "${BUILD_VERSION}.tar.gz"
echo ""

SOURCE_DIR="iputils-${BUILD_VERSION}"
pushd "${SOURCE_DIR}" > /dev/null 2>&1

echo "Patching iputils files ... "
patch < ../iputils.patch
echo ""

echo "Building ... "
./configure --prefix=.
make

popd > /dev/null 2>&1

ln -fn "${SOURCE_DIR}/builddir/ping/ping" .
ln -fn "${SOURCE_DIR}/builddir/arping" .
ln -fn "${SOURCE_DIR}/builddir/tracepath" .
ln -fn "${SOURCE_DIR}/builddir/clockdiff" .
Binary file added iputils/clockdiff
Binary file not shown.
59 changes: 59 additions & 0 deletions iputils/iputils.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
--- configure 2022-11-26 01:07:21.000000000 +0200
+++ configure 2023-03-31 12:40:52.167300078 +0300
@@ -1,14 +1,16 @@
#!/bin/sh

DIR=builddir

+export LDFLAGS="-static-pie"
+
echo "Using './$DIR' as the directory for build output"
echo

if [ $# -ne 0 ]; then
meson configure $DIR
echo
echo 'Configuration can be changed like this:'
echo " meson configure $DIR -Dprefix=/usr"
echo ' More info: http://mesonbuild.com/Configuring-a-build-directory.html'
# See also: http://mesonbuild.com/howtox.html
--- meson.build 2022-11-26 01:07:21.000000000 +0200
+++ meson.build 2023-03-31 12:41:28.679222461 +0300
@@ -1,32 +1,37 @@
# Copyright (c) Iputils Project, 2017-2021

project('iputils', 'c',
default_options : [
'c_std=c99',
'warning_level=3',
'localstatedir=var',
+ 'USE_IDN=false',
],
meson_version : '>=0.40',
version : '20221126') # keep in sync with: git describe | awk -F- '{print $1}'

cc = meson.get_compiler('c')

add_project_arguments(
+ '-fPIC',
'-include', 'config.h',
'-include', 'git-version.h',
language : 'c'
)

conf = configuration_data()
conf.set_quoted('PACKAGE_NAME', meson.project_name())

+conf.set('prefer_static', true)
+conf.set('default_library', 'static')
+
build_arping = get_option('BUILD_ARPING')
build_clockdiff = get_option('BUILD_CLOCKDIFF')
build_ping = get_option('BUILD_PING')
build_tracepath = get_option('BUILD_TRACEPATH')

build_mans = get_option('BUILD_MANS')
build_html_mans = get_option('BUILD_HTML_MANS')
run_tests = not get_option('SKIP_TESTS')

prefix = get_option('prefix')
Binary file added iputils/ping
Binary file not shown.
Binary file added iputils/tracepath
Binary file not shown.