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
Created attachment 579064 [details, diff] proposed patch Thoughts?
Why do these symbols need to be weak at all?
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?
#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.
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.
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?
Yes, does build fine on Cygwin without the weak attribute.
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(-)
[master 19f1ab79dd1] app-portage/portage-utils: version bump for 0.80 RC