-
Notifications
You must be signed in to change notification settings - Fork 40
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 PHP static PIE ELF build #78
Open
gabryon99
wants to merge
1
commit into
unikraft:master
Choose a base branch
from
gabryon99:php-pie
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/php-* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,34 @@ | ||||
# Build PHP as static PIE | ||||
|
||||
Build the [PHP](https://www.php.net/) interpreter as static PIE ELF running on Linux | ||||
|
||||
## Requirements | ||||
|
||||
Make sure the following packages are installed: | ||||
|
||||
* gcc >= 8 | ||||
* GNU Make | ||||
* autoconf | ||||
* bison | ||||
* re2c | ||||
* libxml2 development files | ||||
* libsqlite3 development files | ||||
|
||||
On Ubuntu, you can install these using: | ||||
|
||||
``` | ||||
sudo apt install -y pkg-config build-essential autoconf bison re2c \ | ||||
libxml2-dev libsqlite3-dev | ||||
``` | ||||
|
||||
## Build | ||||
|
||||
The `php` static PIE ELF file is located in the current directory. | ||||
In order to rebuild it you have to run the `build.sh` bash script | ||||
|
||||
The scripts downloads, unpack, patches and build the `php` static PIE ELF file. | ||||
|
||||
## Run | ||||
|
||||
In order to run a script using the static PIE php you can pass it as an argument to the ELF file. | ||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/bin/bash | ||
|
||
PHP_VERSION=8.1.11 | ||
PHP_URL="https://www.php.net/distributions/php-$PHP_VERSION.tar.gz" | ||
|
||
#clean up | ||
rm -rf php-* | ||
|
||
echo -n "Downloading PHP $PHP_VERSION ... " | ||
wget -q "$PHP_URL" | ||
echo "" | ||
|
||
echo -n "Unpacking PHP $PHP_VERSION ... " | ||
tar xzf php-$PHP_VERSION.tar.gz | ||
echo "" | ||
|
||
pushd php-$PHP_VERSION > /dev/null 2>&1 || exit 1 | ||
|
||
echo "Configuring PHP $PHP_VERSION ... " | ||
#iconv and opcache seem to have problems with being in a static build | ||
CFLAGS=-fPIC ./configure | ||
#patch the Makefile | ||
sed -e '/^BUILD_C/s/ -export-dynamic//g' -e 's/^EXTRA_LIBS = .*/EXTRA_LIBS = -lrt -lxml2 -lsqlite3 -lz -llzma -licuuc -licudata -lstdc++ -lm/g' -e '/^EXTRA_LDFLAGS_PROGRAM/s/$/ -static-pie/g' -i Makefile | ||
echo "" | ||
|
||
echo "Building PHP $PHP_VERSION ... " | ||
make -j "$(nproc)" | ||
popd > /dev/null 2>&1 || exit 1 | ||
|
||
ln -fn php-$PHP_VERSION/sapi/cli/php . | ||
|
||
rm -rf php-* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<? echo "Hello world!\n" ?> | ||
|
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.