Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 687560 - app-portage/portage-utils: 0.80_pre breaks on Cygwin due to weak symbols and object file ordering
Summary: app-portage/portage-utils: 0.80_pre breaks on Cygwin due to weak symbols and ...
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:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-06-07 11:09 UTC by Michael Haubenwallner (RETIRED)
Modified: 2019-06-11 07:53 UTC (History)
0 users

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


Attachments
proposed patch (0001-work-around-Cygwin-linker-problem.patch,1.19 KB, patch)
2019-06-07 11:13 UTC, Michael Haubenwallner (RETIRED)
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Haubenwallner (RETIRED) gentoo-dev 2019-06-07 11:09:22 UTC
On Cygwin, the linker seems to fail to resolve weak symbols, when an object file without the symbol but the weak declaration only appears on the linkline before the object file that defines the symbol.

Upstream report: https://cygwin.com/ml/cygwin/2019-06/msg00092.html

Error message is:

/home/haubi/test-20190605/64bit/bin/bash ./libtool  --tag=CC   --mode=link x86_64-pc-cygwin-gcc  -O2 -pipe -Wall -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   -o q.exe 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-qtegrity.o q-quse.o q-qxpak.o q-qmanifest.o  ./libq/libq.la ./autotools/gnulib/libgnu.a -liniparser -lssl -lcrypto -lb2 -lz -L/home/haubi/test-20190605/64bit/usr/lib -lgpgme -lassuan -lgpg-error
libtool: link: x86_64-pc-cygwin-gcc -O2 -pipe -Wall -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 -o .libs/q.exe 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-qtegrity.o q-quse.o q-qxpak.o q-qmanifest.o  ./libq/.libs/libq.a ./autotools/gnulib/libgnu.a -liniparser -lssl -lcrypto -lb2 -lz -L/home/haubi/test-20190605/64bit/usr/lib -lgpgme -lassuan -lgpg-error
q-main.o:main.c:(.text.startup+0xbb7): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `q_main'
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile:1710: q.exe] Error 1
make[2]: Leaving directory '/home/haubi/test-20190605/64bit/var/tmp/portage/app-portage/portage-utils-0.80_pre20190605/work/portage-utils-0.80_pre20190605'
make[1]: *** [Makefile:2084: all-recursive] Error 1
make[1]: Leaving directory '/home/haubi/test-20190605/64bit/var/tmp/portage/app-portage/portage-utils-0.80_pre20190605/work/portage-utils-0.80_pre20190605'
make: *** [Makefile:1606: all] Error 2
 * ERROR: app-portage/portage-utils-0.80_pre20190605::gentoo_prefix failed (compile phase):
 *   emake failed
Comment 1 Michael Haubenwallner (RETIRED) gentoo-dev 2019-06-07 11:13:36 UTC
Created attachment 579064 [details, diff]
proposed patch

Thoughts?
Comment 2 Michael Haubenwallner (RETIRED) gentoo-dev 2019-06-07 11:15:32 UTC
Why do these symbols need to be weak at all?
Comment 3 Fabian Groffen gentoo-dev 2019-06-07 11:39:48 UTC
I'm surprised, which symbols are weak?  I don't even know how to generate those to be honest.  I hope it doesn't come from gnulib.

q_main is never declared, is that's the problem?
Comment 4 Fabian Groffen gentoo-dev 2019-06-07 11:52:23 UTC
#define DECLARE_APPLET(applet) \
    extern int applet##_main(int, char **) __attribute__((weak));

Oh.  Let me dig a bit deeper.  Perhaps we can loose the weak attribute thing here now since we build in a more normal way nowadays.
Comment 5 Michael Haubenwallner (RETIRED) gentoo-dev 2019-06-07 12:00:39 UTC
Upstream answer is:
> Unfortunately, PE doesn't really have a concept of weak symbols like
> ELF, and is known to be broken in binutils.

Not sure how C++ does with weak symbols then.

Anyway, removing the weak attribute here should be fine.
Comment 6 Fabian Groffen gentoo-dev 2019-06-07 12:04:32 UTC
diff --git a/applets.h b/applets.h
index 902e664..d8383d4 100644
--- a/applets.h
+++ b/applets.h
@@ -35,8 +35,7 @@ extern int    getopt_long(int, char * const *, const char *,
 /* applet prototypes */
 typedef int (*APPLET)(int, char **);
 
-#define DECLARE_APPLET(applet) \
-       extern int applet##_main(int, char **) __attribute__((weak));
+#define DECLARE_APPLET(applet) extern int applet##_main(int, char **);
 DECLARE_APPLET(q)
 DECLARE_APPLET(qatom)
 DECLARE_APPLET(qcheck)


This doesn't change/break anything on x64-solaris, does this fix the problem on  Cygwin?
Comment 7 Michael Haubenwallner (RETIRED) gentoo-dev 2019-06-07 12:18:28 UTC
Yes, does build fine on Cygwin without the weak attribute.
Comment 8 Larry the Git Cow gentoo-dev 2019-06-07 12:20:44 UTC
The bug has been referenced in the following commit(s):

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

commit 3b00486fb75941e66bcc829d4e0481d6a349cc82
Author:     Fabian Groffen <grobian@gentoo.org>
AuthorDate: 2019-06-07 12:19:32 +0000
Commit:     Fabian Groffen <grobian@gentoo.org>
CommitDate: 2019-06-07 12:19:32 +0000

    applets.h: loose __weak__ attribute stuff
    
    defining this attribute breaks Cygwin, but more importantly it is not
    necessary with the current (much more normal) way of building and
    linking q.
    
    Bug: https://bugs.gentoo.org/687560
    Signed-off-by: Fabian Groffen <grobian@gentoo.org>

 applets.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
Comment 9 Fabian Groffen gentoo-dev 2019-06-11 07:53:26 UTC
[master 19f1ab79dd1] app-portage/portage-utils: version bump for 0.80 RC