Skip to content

Commit

Permalink
Add HAProxy static PIE ELF
Browse files Browse the repository at this point in the history
Add HAProxy static PIE ELF. Add instructions and helper scripts to build HAProxy as a static PIE ELF.

Co-authored-by: Gabriele Pappalardo <leleattolo99@gmail.com>
Co-authored-by: Alberto Zurini <alberto.zurini@gmail.com>
Co-authored-by: Federico Bertossi <livebymax@gmail.com>
Signed-off-by: Alessandro Grassi <alessandrograssi17@gmail.com>
  • Loading branch information
4 people committed Oct 23, 2022
1 parent 5974451 commit b1a77cd
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
18 changes: 18 additions & 0 deletions haproxy/Makefile.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--- Makefile_OLD.txt 2022-10-23 16:24:37.113951164 +0200
+++ Makefile 2022-10-23 15:25:44.686153369 +0200
@@ -326,13 +326,13 @@
# These CFLAGS contain general optimization options, CPU-specific optimizations
# and debug flags. They may be overridden by some distributions which prefer to
# set all of them at once instead of playing with the CPU and DEBUG variables.
-CFLAGS = $(ARCH_FLAGS) $(CPU_CFLAGS) $(DEBUG_CFLAGS) $(SPEC_CFLAGS)
+CFLAGS = -fPIC $(ARCH_FLAGS) $(CPU_CFLAGS) $(DEBUG_CFLAGS) $(SPEC_CFLAGS)

#### Common LDFLAGS
# These LDFLAGS are used as the first "ld" options, regardless of any library
# path or any other option. They may be changed to add any linker-specific
# option at the beginning of the ld command line.
-LDFLAGS = $(ARCH_FLAGS) -g
+LDFLAGS = -static-pie $(ARCH_FLAGS) -g

#### list of all "USE_*" options. These ones must be updated if new options are
# added, so that the relevant options are properly added to the CFLAGS and to
27 changes: 27 additions & 0 deletions haproxy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Build HAProxy as static PIE

Build the [HAProxy](https://git.haproxy.org/): The Reliable, High Performance TCP/HTTP Load Balancer as a static PIE ELF running on Linux.

## Requirements

Make sure the following packages are installed:
* gcc >= 8 (required for the `-static-pie` linking option)
* autotools
* GNU Make
* zlib development files
* OpenSSL development files

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

```
$ sudo apt install build-essential zlib1g-dev libssl-dev
```

## Build

The `HAProxy` static PIE ELF is located in the current folder.
If you want to rebuild it, run:

```
$ ./build.sh
```
16 changes: 16 additions & 0 deletions haproxy/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
\#!/bin/bash

# Clean up.
rm -fr haproxy-git

echo -n "Downloading HAProxy ... "
git clone https://github.com/haproxy/haproxy.git haproxy-git
echo ""
echo -n "Building HAProxy ... "
pushd haproxy-git > /dev/null 2>&1
patch Makefile < ../Makefile.patch
make TARGET=linux-glibc-legacy
popd > /dev/null 2>&1

cp haproxy-git/haproxy .
rm -fr haproxy-git
Binary file added haproxy/haproxy
Binary file not shown.

0 comments on commit b1a77cd

Please sign in to comment.