Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 841898 - app-portage/portage-utils static USE flag does not create a static q binary
Summary: app-portage/portage-utils static USE flag does not create a static q binary
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Fabian Groffen
URL: https://github.com/gentoo/portage-uti...
Whiteboard:
Keywords: PullRequest
Depends on:
Blocks:
 
Reported: 2022-05-01 02:32 UTC by genBTC
Modified: 2022-08-29 06:41 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
build.log with static USE flag - did not produce static binary (portage-utils-build-log.txt,162.41 KB, text/plain)
2022-05-01 02:33 UTC, genBTC
Details
emerge --info (emergeinfo.txt,6.84 KB, text/plain)
2022-05-01 06:20 UTC, genBTC
Details
recent patch does not solve. build.log showing no -static (portage-utils-0.94.1-fail.txt,177.51 KB, text/plain)
2022-08-17 20:50 UTC, genBTC
Details

Note You need to log in before you can comment on or make changes to this bug.
Description genBTC 2022-05-01 02:32:06 UTC
PROBLEM: 
trying to use +static on app-portage/portage-utils (with all other flags turned off for simplicity) doesnt produce a static binary, its still dynamically linked (as reported per the file command and ldd command)
we stumbled upon this while trying to recover another system with broken libc.
I am the 2nd person to reproduce this.

ANALYSIS:
the ./configure script rightly enables --enable-static , but -static is never actually passed to the compiler during the final link stage.
libtool is responsible for calling this stage, and the internals of libtool are virtually impossible for me to reckon with.
I tried calling ./configure with "--enable-static --disable-shared" but that still did not solve it.
If I had to guess I don't think its a problem with autotools/gnulib but maybe the libq part, or something is just wrong with libtool.

MANUAL WORKAROUND:
I was able to confirm that calling GCC manually with -static achieved the proper static linkage.

MANUAL COMPILE COMMAND that resulted in SUCCESS:
x86_64-pc-linux-gnu-gcc -static -Wall -march=native -O2 -pipe -Wunused -Wimplicit -Wshadow -Wformat=2 -Wmissing-declarations -Wwrite-strings -Wbad-function-cast -Wnested-externs -Wcomment -Winline -Wchar-subscripts -Wcast-align -Wsequence-point -Wold-style-definition -Wextra -Wno-format-nonliteral -Wno-expansion-to-defined  -Wl,-O1 -Wl,--as-needed -o q q-main.o q-q.o q-qatom.o q-qcheck.o q-qdepends.o q-qfile.o q-qgrep.o q-qkeyword.o q-qlist.o q-qlop.o q-qmerge.o q-qpkg.o q-qsearch.o q-qsize.o q-qtbz2.o q-quse.o q-qwhich.o q-qxpak.o ./libq/.libs/libq.a ./autotools/gnulib/libgnu.a

(note my deliberate inclusion of -static, and omission of libq .la linker script to just passing libq .a directly)

I will include my normal portage build log for reference, but you should be able to reproduce this no problem on your 
end.

Thank you

Reproducible: Always
Comment 1 genBTC 2022-05-01 02:33:30 UTC
Created attachment 775715 [details]
build.log with static USE flag - did not produce static binary

(I always print the ./configure --help in my /etc/portage/bashrc) 
Other than that, its a very normal default build with static use flag.
Comment 2 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-05-01 02:35:21 UTC
For completeness, please include emerge --info.
Comment 3 genBTC 2022-05-01 06:20:09 UTC
Created attachment 775721 [details]
emerge --info

from the system the build.log is from.
the bug is confirmed on a 3rd system also.
Comment 4 Fabian Groffen gentoo-dev 2022-05-22 09:30:09 UTC
I don't see the static libtool mode kicking in either, clueless at the moment as to why
Comment 5 Fabian Groffen gentoo-dev 2022-05-25 13:01:41 UTC
can you try this:

diff --git a/Makefile.am b/Makefile.am
index 90c868b..b9f7729 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -86,6 +86,7 @@ q_LDADD = \
        $(LIB_EACCESS) \
        $(SENDFILE_LIBS) \
        $(NULL)
+q_LDFLAGS = $(LDFLAGS_EXEC)
 
 if QMANIFEST_ENABLED
 q_SOURCES += qmanifest.c
diff --git a/configure.ac b/configure.ac
index 013e831..344516b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -51,6 +51,13 @@ AC_DEFINE_UNQUOTED([CONFIG_EPREFIX], ["$with_eprefix"],
                                   [Gentoo Prefix offset path])
 AC_SUBST([CONFIG_EPREFIX], ["$with_eprefix"])
 
+AC_ARG_ENABLE([static-bin], [AS_HELP_STRING([--enable-static-bin],
+                         [link static q executable])])
+if test "x${enable_static_bin}" = xyes ; then
+       LDFLAGS_EXEC="-static"
+fi
+AC_SUBST([LDFLAGS_EXEC])
+
 AC_ARG_ENABLE([qmanifest], [AS_HELP_STRING([--enable-qmanifest],
                          [support qmanifest applet])],
                          [], [enable_qmanifest=auto])


(autoreconf and then ./configure --enable-static-bin)
Comment 6 genBTC 2022-08-17 20:50:50 UTC
Created attachment 799991 [details]
recent patch does not solve. build.log showing no -static

The last patch for adding the --enable-static-bin option did not actually produce a static binary.
I have ensured the patch merged as you intended, but with no result.
I have tested recent portage-utils 0.94.1 now too and uploaded the build.log.

# file /usr/bin/q
/usr/bin/q: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, stripped
Comment 7 Larry the Git Cow gentoo-dev 2022-08-28 12:26:19 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=1ad6040d95a9c8733cec4388ac6cb3c73e8ddf0d

commit 1ad6040d95a9c8733cec4388ac6cb3c73e8ddf0d
Author:     David Seifert <soap@gentoo.org>
AuthorDate: 2022-08-28 11:40:31 +0000
Commit:     Fabian Groffen <grobian@gentoo.org>
CommitDate: 2022-08-28 11:51:06 +0000

    Remove libtool
    
    * Libtool was only used for convenience libraries, which can
      be done in vanilla Automake. This allows passing `static`
      in LDFLAGS.
    
    Bug: https://bugs.gentoo.org/841898
    Signed-off-by: David Seifert <soap@gentoo.org>
    Signed-off-by: Fabian Groffen <grobian@gentoo.org>

 Makefile.am                    | 2 +-
 configure.ac                   | 3 +--
 libq/Makefile.am               | 6 +++---
 tests/atom_explode/Makefile.am | 2 +-
 tests/copy_file/Makefile.am    | 2 +-
 tests/mkdir/Makefile.am        | 2 +-
 tests/rmspace/Makefile.am      | 2 +-
 7 files changed, 9 insertions(+), 10 deletions(-)
Comment 8 Larry the Git Cow gentoo-dev 2022-08-28 21:42:59 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=152cba16dd90e36b4e8abd4c4445adee321a37d3

commit 152cba16dd90e36b4e8abd4c4445adee321a37d3
Author:     David Seifert <soap@gentoo.org>
AuthorDate: 2022-08-28 21:42:45 +0000
Commit:     David Seifert <soap@gentoo.org>
CommitDate: 2022-08-28 21:42:45 +0000

    app-portage/portage-utils: add 0.94.2
    
    Closes: https://bugs.gentoo.org/867076
    Bug: https://bugs.gentoo.org/841898
    Signed-off-by: David Seifert <soap@gentoo.org>

 app-portage/portage-utils/Manifest                 |  1 +
 .../portage-utils/portage-utils-0.94.2.ebuild      | 75 ++++++++++++++++++++++
 2 files changed, 76 insertions(+)
Comment 9 Fabian Groffen gentoo-dev 2022-08-29 06:40:43 UTC
0.94.2 should do it with -static in LDFLAGS.