From 44cb155baf47047acbe9d111e00e80021f0c3798 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Wed, 2 Feb 2022 07:26:35 +0500 Subject: [PATCH] Main: generate position-independent code by default Disable with "--disable-pic" --- .cirrus.yml | 8 ++++---- .github/workflows/main.yml | 4 ++-- .github/workflows/mruby.yml | 2 +- .github/workflows/ruby.yml | 4 ++-- .github/workflows/rust.yml | 2 +- ChangeLog | 5 +++++ Makefile.am | 16 ++++++++-------- README.md | 6 ++++-- config/dev-cross-i386 | 4 ++-- config/dev-cross-riscv64 | 4 ++-- config/dev-cross-x86_64 | 4 ++-- config/dev-native | 2 -- config/root-cross-i386-linux | 4 ++-- config/root-cross-riscv64-linux | 4 ++-- config/root-cross-x86_64-linux | 4 ++-- config/root-native | 2 -- configure.ac | 7 +++++++ 17 files changed, 46 insertions(+), 36 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 63c1957..f314478 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -10,7 +10,7 @@ main_freebsd_task: - pkg install --yes autoconf automake main_build_script: - ./autogen.sh - - ./configure --enable-tests CFLAGS='-O3 -fPIC' + - ./configure --enable-tests CFLAGS='-O3' - make - sudo make install main_test_script: @@ -25,7 +25,7 @@ mruby_freebsd_task: - unzip mruby-3.0.0.zip main_build_script: - ./autogen.sh - - ./configure CFLAGS='-O3 -fPIC' + - ./configure CFLAGS='-O3' - make - sudo make install mruby_test_script: @@ -45,7 +45,7 @@ ruby_freebsd_task: - sudo make install main_build_script: - ./autogen.sh - - ./configure CFLAGS='-O3 -fPIC' + - ./configure CFLAGS='-O3' - make - sudo make install ruby_build_script: @@ -67,7 +67,7 @@ rust_freebsd_task: - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y main_build_script: - ./autogen.sh - - ./configure CFLAGS='-O3 -fPIC' + - ./configure CFLAGS='-O3' - make - sudo make install rust_test_script: diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 45bd3e8..2a46c9c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,7 +22,7 @@ jobs: - name: autogen run: ./autogen.sh - name: configure - run: ./configure --enable-tests CC='${{matrix.cc}}' CFLAGS='${{matrix.opt}} -fPIC' + run: ./configure --enable-tests CC='${{matrix.cc}}' CFLAGS='${{matrix.opt}}' - name: make run: make - name: check @@ -51,7 +51,7 @@ jobs: - name: autogen run: ./autogen.sh - name: configure - run: ./configure --enable-tests --without-all CFLAGS='-fPIC' + run: ./configure --enable-tests --without-all - name: make run: make - name: check diff --git a/.github/workflows/mruby.yml b/.github/workflows/mruby.yml index d09e311..6b85a2a 100644 --- a/.github/workflows/mruby.yml +++ b/.github/workflows/mruby.yml @@ -18,7 +18,7 @@ jobs: - name: autogen run: ./autogen.sh - name: configure - run: ./configure CFLAGS='-O3 -fPIC' + run: ./configure CFLAGS='-O3' - name: make run: make - name: install diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 42bf3cd..8b7a5ac 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -19,7 +19,7 @@ jobs: - name: autogen run: ./autogen.sh - name: configure - run: ./configure CFLAGS='-O3 -fPIC' + run: ./configure CFLAGS='-O3' - name: make run: make - name: install @@ -51,7 +51,7 @@ jobs: - name: autogen run: ./autogen.sh - name: configure - run: ./configure --without-all CFLAGS='-O3 -fPIC' + run: ./configure --without-all CFLAGS='-O3' - name: make run: make - name: install diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 7108c25..3697f7c 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -18,7 +18,7 @@ jobs: - name: autogen run: ./autogen.sh - name: configure - run: ./configure CFLAGS='-O3 -fPIC' + run: ./configure CFLAGS='-O3' - name: make run: make - name: install diff --git a/ChangeLog b/ChangeLog index 21d6e59..a568c84 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2022-02-02 Alex Kotov + + * configure.ac: Generate position-independent code by default, disable with + "--disable-pic" + 2022-02-01 Alex Kotov * configure.ac: Generate headers conditionally depending on options diff --git a/Makefile.am b/Makefile.am index 8e75131..64f6687 100644 --- a/Makefile.am +++ b/Makefile.am @@ -17,14 +17,6 @@ libkernaux_a_SOURCES = \ src/assert.c \ src/libc.c -if ENABLE_TESTS -TESTS = \ - examples/assert_guards \ - examples/assert_simple \ - examples/panic_guards \ - examples/panic_simple -endif - if ASM_I386 libkernaux_a_SOURCES += src/asm/i386.S endif @@ -37,6 +29,14 @@ if ASM_X86_64 libkernaux_a_SOURCES += src/asm/x86_64.S endif +if ENABLE_TESTS +TESTS = \ + examples/assert_guards \ + examples/assert_simple \ + examples/panic_guards \ + examples/panic_simple +endif + if WITH_CMDLINE libkernaux_a_SOURCES += src/cmdline.c if ENABLE_TESTS diff --git a/README.md b/README.md index 808b4ac..0403da3 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,7 @@ stable options. * `--enable-bloat`, disable with `--disable-bloat` * `--enable-float`, disable with `--disable-float` +* `--enable-pic`, disable with `--disable-pic` #### Packages @@ -121,7 +122,7 @@ Tips ``` ./autogen.sh -./configure CFLAGS='-fPIC' +./configure make sudo make install ``` @@ -133,7 +134,7 @@ environment. ``` ./autogen.sh -./configure --enable-tests CFLAGS='-fPIC' +./configure --enable-tests make ``` @@ -150,6 +151,7 @@ without it in `$PATH`: ``` ./configure \ --host='i386-elf' \ + --disable-pic \ --with-libc \ AR="$(which i386-elf-ar)" \ CC="$(which i386-elf-gcc)" \ diff --git a/config/dev-cross-i386 b/config/dev-cross-i386 index 3225901..b14b26c 100755 --- a/config/dev-cross-i386 +++ b/config/dev-cross-i386 @@ -14,6 +14,6 @@ export AR="$CROSS-ar" export CC="$CROSS-gcc" export RANLIB="$CROSS-ranlib" -export CFLAGS='-ffreestanding -nostdlib -fno-builtin -fno-stack-protector -fno-pic' +export CFLAGS='-ffreestanding -nostdlib -fno-builtin -fno-stack-protector' -"$REPO/configure" --host="$HOST" --prefix="$PREFIX" --with-libc +"$REPO/configure" --host="$HOST" --prefix="$PREFIX" --disable-pic --with-libc diff --git a/config/dev-cross-riscv64 b/config/dev-cross-riscv64 index a3dc786..8db23f0 100755 --- a/config/dev-cross-riscv64 +++ b/config/dev-cross-riscv64 @@ -14,6 +14,6 @@ export AR="$CROSS-ar" export CC="$CROSS-gcc" export RANLIB="$CROSS-ranlib" -export CFLAGS='-ffreestanding -nostdlib -fno-builtin -fno-stack-protector -fno-pic' +export CFLAGS='-ffreestanding -nostdlib -fno-builtin -fno-stack-protector' -"$REPO/configure" --host="$HOST" --prefix="$PREFIX" --with-libc +"$REPO/configure" --host="$HOST" --prefix="$PREFIX" --disable-pic --with-libc diff --git a/config/dev-cross-x86_64 b/config/dev-cross-x86_64 index 68403bc..951d4bd 100755 --- a/config/dev-cross-x86_64 +++ b/config/dev-cross-x86_64 @@ -14,6 +14,6 @@ export AR="$CROSS-ar" export CC="$CROSS-gcc" export RANLIB="$CROSS-ranlib" -export CFLAGS='-ffreestanding -nostdlib -fno-builtin -fno-stack-protector -fno-pic -mabi=sysv -mcmodel=kernel -mno-80387 -mno-red-zone' +export CFLAGS='-ffreestanding -nostdlib -fno-builtin -fno-stack-protector -mabi=sysv -mcmodel=kernel -mno-80387 -mno-red-zone' -"$REPO/configure" --host="$HOST" --prefix="$PREFIX" --with-libc +"$REPO/configure" --host="$HOST" --prefix="$PREFIX" --disable-pic --with-libc diff --git a/config/dev-native b/config/dev-native index 17b1549..4e454f7 100755 --- a/config/dev-native +++ b/config/dev-native @@ -7,6 +7,4 @@ if [ -f "$REPO/Makefile" ]; then make -C "$REPO" distclean; fi PREFIX="$REPO/dest/dev-native" -export CFLAGS='-fPIC' - "$REPO/configure" --prefix="$PREFIX" --enable-tests diff --git a/config/root-cross-i386-linux b/config/root-cross-i386-linux index ca17ed4..833cbec 100755 --- a/config/root-cross-i386-linux +++ b/config/root-cross-i386-linux @@ -14,6 +14,6 @@ export AR="$TARGET-ar" export CC="$TARGET-gcc" export RANLIB="$TARGET-ranlib" -export CFLAGS='-ffreestanding -nostdlib -fno-builtin -fno-stack-protector -fno-pic' +export CFLAGS='-ffreestanding -nostdlib -fno-builtin -fno-stack-protector' -"$REPO/configure" --host="$HOST" --prefix="$PREFIX" --with-libc +"$REPO/configure" --host="$HOST" --prefix="$PREFIX" --disable-pic --with-libc diff --git a/config/root-cross-riscv64-linux b/config/root-cross-riscv64-linux index 2ba2f4f..53bbb05 100755 --- a/config/root-cross-riscv64-linux +++ b/config/root-cross-riscv64-linux @@ -14,6 +14,6 @@ export AR="$TARGET-ar" export CC="$TARGET-gcc" export RANLIB="$TARGET-ranlib" -export CFLAGS='-ffreestanding -nostdlib -fno-builtin -fno-stack-protector -fno-pic' +export CFLAGS='-ffreestanding -nostdlib -fno-builtin -fno-stack-protector' -"$REPO/configure" --host="$HOST" --prefix="$PREFIX" --with-libc +"$REPO/configure" --host="$HOST" --prefix="$PREFIX" --disable-pic --with-libc diff --git a/config/root-cross-x86_64-linux b/config/root-cross-x86_64-linux index 867c266..7d184c4 100755 --- a/config/root-cross-x86_64-linux +++ b/config/root-cross-x86_64-linux @@ -14,6 +14,6 @@ export AR="$TARGET-ar" export CC="$TARGET-gcc" export RANLIB="$TARGET-ranlib" -export CFLAGS='-ffreestanding -nostdlib -fno-builtin -fno-stack-protector -fno-pic -mabi=sysv -mcmodel=kernel -mno-80387 -mno-red-zone' +export CFLAGS='-ffreestanding -nostdlib -fno-builtin -fno-stack-protector -mabi=sysv -mcmodel=kernel -mno-80387 -mno-red-zone' -"$REPO/configure" --host="$HOST" --prefix="$PREFIX" --with-libc +"$REPO/configure" --host="$HOST" --prefix="$PREFIX" --disable-pic --with-libc diff --git a/config/root-native b/config/root-native index 4fc02e6..4018f45 100755 --- a/config/root-native +++ b/config/root-native @@ -5,6 +5,4 @@ set -e REPO="$(realpath "$(dirname "$(realpath "$0")")/..")" if [ -f "$REPO/Makefile" ]; then make -C "$REPO" distclean; fi -export CFLAGS='-fPIC' - "$REPO/configure" --enable-tests diff --git a/configure.ac b/configure.ac index 7ed72b5..b859b18 100644 --- a/configure.ac +++ b/configure.ac @@ -16,6 +16,7 @@ AC_CANONICAL_HOST dnl Features (enabled by default) AC_ARG_ENABLE([bloat], AS_HELP_STRING([--disable-bloat], [disable unnecessary heavy binary data])) AC_ARG_ENABLE([float], AS_HELP_STRING([--disable-float], [disable floating-point arithmeric])) +AC_ARG_ENABLE([pic], AS_HELP_STRING([--disable-pic], [do not generate position-independent code])) dnl Features (disabled by default) AC_ARG_ENABLE([tests], AS_HELP_STRING([--enable-tests], [enable tests and examples])) @@ -89,6 +90,7 @@ AM_CONDITIONAL([ASM_X86_64], [test "$host_cpu" = x86_64]) dnl Features (enabled by default) AM_CONDITIONAL([ENABLE_BLOAT], [test "$enable_bloat" != no]) AM_CONDITIONAL([ENABLE_FLOAT], [test "$enable_float" != no]) +AM_CONDITIONAL([ENABLE_PIC], [test "$enable_pic" != no]) dnl Features (disabled by default) AM_CONDITIONAL([ENABLE_TESTS], [test "$enable_tests" = yes]) @@ -124,6 +126,7 @@ AS_IF([test "$host_cpu" = x86_64], [AC_DEFINE([ASM_X86_64], [1] dnl Features (enabled by default) AS_IF([test "$enable_bloat" != no], [AC_DEFINE([ENABLE_BLOAT], [1], [enabled unnecessary heavy binary data])]) AS_IF([test "$enable_float" != no], [AC_DEFINE([ENABLE_FLOAT], [1], [enabled floating-point arithmeric])]) +AS_IF([test "$enable_pic" != no], [AC_DEFINE([ENABLE_PIC], [1], [generate position-independent code])]) dnl Features (disabled by default) AS_IF([test "$enable_tests" = yes], [AC_DEFINE([ENABLE_TESTS], [1], [enabled tests and examples])]) @@ -179,6 +182,10 @@ AS_IF([test "$with_libc_strnlen" != yes], [AC_SUBST([comment_line_libc_strnlen], +AS_IF([test "$enable_pic" != no], [CFLAGS+=' -fpic '], [CFLAGS+=' -fno-pic']) + + + AM_INIT_AUTOMAKE([1.9 subdir-objects]) AC_CONFIG_FILES([