diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 88015d93..2c736003 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -89,7 +89,7 @@ jobs: path: dist - name: Build binaries env: - CXXFLAGS: "-D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wformat -Werror=format-security -O2 -static" + CXXFLAGS: "-D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wformat -Werror=format-security -O2" run: | cat < build.sh set -e @@ -98,7 +98,7 @@ jobs: tar -xf dist/*.tar.bz2 rm -f dist/* cd patchelf-* - ./configure --prefix /patchelf + ./configure --prefix /patchelf --with-static make check || (cat tests/test-suite.log; exit 1) make install-strip cd - diff --git a/configure.ac b/configure.ac index fee6302f..ccb0bd40 100644 --- a/configure.ac +++ b/configure.ac @@ -41,5 +41,10 @@ AC_ARG_WITH([ubsan], ) AM_CONDITIONAL([WITH_UBSAN], [test x"$with_ubsan" = xyes]) +AC_ARG_WITH([static], + AS_HELP_STRING([--with-static], [Build static binary]) +) +AM_CONDITIONAL([WITH_STATIC], [test x"$with_static" = xyes]) + AC_CONFIG_FILES([Makefile src/Makefile tests/Makefile patchelf.spec]) AC_OUTPUT diff --git a/src/Makefile.am b/src/Makefile.am index 93e92d8c..26379933 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -17,6 +17,10 @@ AM_CXXFLAGS += $(SAN_FLAGS) endif endif +if WITH_STATIC +AM_CXXFLAGS += -static +endif + bin_PROGRAMS = patchelf patchelf_SOURCES = patchelf.cc elf.h patchelf.h diff --git a/tests/Makefile.am b/tests/Makefile.am index b08929f1..f6e6122a 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -82,7 +82,7 @@ export NIX_LDFLAGS= simple_SOURCES = simple.c # no -fpic for simple.o simple_CFLAGS = -simple_LDFLAGS = -Wl,-z,noexecstack +simple_LDFLAGS = -Wl,-z,noexecstack -no-pie simple_pie_SOURCES = simple.c simple_pie_CFLAGS = -fPIC -pie @@ -173,7 +173,7 @@ libmany_syms_so_LDFLAGS = $(LDFLAGS_sharedlib) no_rpath_SOURCES = no-rpath.c # no -fpic for no-rpath.o no_rpath_CFLAGS = -no_rpath_LDFLAGS = +no_rpath_LDFLAGS = -no-pie contiguous_note_sections_SOURCES = contiguous-note-sections.s contiguous-note-sections.ld contiguous_note_sections_LDFLAGS = -nostdlib -T $(srcdir)/contiguous-note-sections.ld