[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Problems building phast against clapack



[ Hmpf, multiple X-Debbugs-Cc don't work the way I expected, hence
  attaching my initial email. Sorry for the noise on
  debian-med-packaging@, that's the only of the initial X-Debbugs-Cc
  that got through. ]

This is now tracked in:
https://bugs.debian.org/826253

Regards,
Christian
--- Begin Message ---
Package: libf2c2
Severity: serious
Version: 20130926-1
Tags: patch
Justification: violation of Debian policy 10.2 (libraries may
 not depend on symbols that they don't import)

(cf. discussion on debian-mentors:
https://lists.debian.org/debian-mentors/2016/06/msg00090.html
+ followups)

On 06/03/2016 09:59 AM, Andreas Tille wrote:
> ...
> ../munge-help.sh consEntropy.help_src > consEntropy.help
> gcc -O3 -Wall -I/build/phast-1.4/src/util/../../include -DPHAST_VERSION=\"v1.3\" -DPHAST_HOME=\"/build/phast-1.4/src/util/../..\" -I/build/phast-1.4/src/util/../../src/lib/pcre -fno-strict-aliasing -I/usr/lib/INCLUDE -I/usr/lib/F2CLIBS -c indelHistory.c -o indelHistory.o
> gcc -L/build/phast-1.4/src/util/../../lib  -L/usr/lib/F2CLIBS   -o /build/phast-1.4/src/util/../../bin/indelHistory indelHistory.o -lphast -lclapack -lctmg -lcblas -lc -lf2c -lm
> /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libf2c.so: undefined reference to `MAIN__'
> collect2: error: ld returned 1 exit status
> Makefile:20: recipe for target '/build/phast-1.4/src/util/../../bin/indelHistory' failed

So what appears to be the case is the following: libf2c.so has
a function main(), which will be called with fortran programs
converted via f2c, because there needs to be some setup code
to happen before the actual main converted Fortran program can
be run. This main implementation then calls MAIN__, which f2c
generates for converted Fortran programs - but not subroutines.

As far as I can tell, this has the unfortunate consequence that
f2c can't really be used to generate libraries that are used
from anything but other code that is converted via f2c.

Steps to reproduce this issue:

#include <stdio.h>
int main() { printf("Hello World!\n"); }

gcc -Wall -o hello hello.c -lf2c

In this trivial example, this is not a huge issue (why would
you want to do so), but you can see the problem it creates in
other software.

Fortunately, there's a way out of this, by adding a weak alias
for MAIN__ in libf2c2's main.c. I've attached a patch that does
this (and also makes the main function in libf2c.so weak, just
in case). I've tested it in a sid chroot and at least my simple
hello example now compiles and runs. (Although linking that
against f2c is rather useless... But other programs will now
hopefully also work.)

Regards,
Christian
Description: Make MAIN__ a weak symbol
 Make MAIN__ a weak symbol, to make sure that non-f2c binaries can link
 against libraries created by it. Also make main() a weak symbol, just
 in case, because we really don't want to override a C program's main
 routine.
Author: Christian Seiler <christian@iwakd.de>

--- a/main.c
+++ b/main.c
@@ -53,6 +53,20 @@ extern int MAIN__(void);
 #define Int int
 #endif
 
+/* Make main() a weak symbol. */
+int main(int argc, char **argv) __attribute__((weak));
+
+/* Create dummy MAIN__ function and make MAIN__ a weak alias to it.
+ * If linked against a program that exports MAIN__, i.e. one compiled
+ * by f2c, this MAIN__ will resolve to the program's MAIN__ instead,
+ * whereas normal C programs will still be able to link against this
+ * library. */
+static int weak_MAIN__()
+{
+  return -1;
+}
+extern int MAIN__() __attribute__((weak, alias("weak_MAIN__")));
+
 static VOID sigfdie(Sigarg)
 {
 Use_Sigarg;

Attachment: signature.asc
Description: OpenPGP digital signature


--- End Message ---

Attachment: signature.asc
Description: OpenPGP digital signature


Reply to: