ambs / Text-BibTeX

Text::BibTeX
6 stars 9 forks source link

ld 2.3.0 doesn't recognize -Wl,-soname #34

Open vadimkantorov opened 3 years ago

vadimkantorov commented 3 years ago

I'm building Text::BibTeX manually with an almost-static build of Perl in order to eventually port biber to WebAssembly. Getting build errors from Text::BibTeX. Could you advise how to hack around the build script?

ld -o btparse/src/libbtparse.so btparse/src/init.o btparse/src/input.o btparse/src/bibtex.o btparse/src/err.o btparse/src/scan.o btparse/src/error.o btparse/src/lex_auxiliary.o btparse/src/parse_auxiliary.o btparse/src/bibtex_ast.o btparse/src/sym.o btparse/src/util.o btparse/src/postprocess.o btparse/src/macros.o btparse/src/traversal.o btparse/src/modify.o btparse/src/names.o btparse/src/tex_tree.o btparse/src/string_util.o btparse/src/format_name.o -Wl,-soname=libbtparse.so
#ld: unrecognized option '-Wl,-soname=libbtparse.so'

ld -o btparse/src/libbtparse.so btparse/src/init.o btparse/src/input.o btparse/src/bibtex.o btparse/src/err.o btparse/src/scan.o btparse/src/error.o btparse/src/lex_auxiliary.o btparse/src/parse_auxiliary.o btparse/src/bibtex_ast.o btparse/src/sym.o btparse/src/util.o btparse/src/postprocess.o btparse/src/macros.o btparse/src/traversal.o btparse/src/modify.o btparse/src/names.o btparse/src/tex_tree.o btparse/src/string_util.o btparse/src/format_name.o
# ld: warning: cannot find entry symbol _start; defaulting to 0000000000400120
# btparse/src/input.o: In function `bt_parse_entry_s':
# input.c:(.text+0x1db): undefined reference to `free'
# input.c:(.text+0x20e): undefined reference to `__stack_chk_fail'

ld -o btparse/src/libbtparse.so btparse/src/init.o btparse/src/input.o btparse/src/bibtex.o btparse/src/err.o btparse/src/scan.o btparse/src/error.o btparse/src/lex_auxiliary.o btparse/src/parse_auxiliary.o btparse/src/bibtex_ast.o btparse/src/sym.o btparse/src/util.o btparse/src/postprocess.o btparse/src/macros.o btparse/src/traversal.o btparse/src/modify.o btparse/src/names.o btparse/src/tex_tree.o btparse/src/string_util.o btparse/src/format_name.o -lc
# ld: warning: cannot find entry symbol _start; defaulting to 0000000000400f00
vadimkantorov commented 3 years ago

After letting it error out, doing linking manually and resuming, I get:

cc -Ibtparse/src -I/home/vadimkantorov/buildbiber/build/native/perl/../prefix/lib/5.30.0/x86_64-linux/CORE -c -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -O -o xscode/BibTeX.o xscode/BibTeX.c
ld -o blib/arch/auto/Text/BibTeX/BibTeX.none xscode/BibTeX.o xscode/btxs_support.o -Lbtparse/src -lbtparse
# ld: error in btparse/src/libbtparse.so(.eh_frame); no .eh_frame_hdr table will be created.
# ld: warning: cannot find entry symbol _start; defaulting to 0000000000400f00
# xscode/BibTeX.o: In function `XS_Text__BibTeX_macro_text':
# BibTeX.c:(.text+0xb): undefined reference to `PL_markstack_ptr'
# BibTeX.c:(.text+0x16): undefined reference to `PL_markstack_ptr'
# BibTeX.c:(.text+0x24): undefined reference to `PL_stack_base'
# BibTeX.c:(.text+0x2f): undefined reference to `PL_stack_sp'
# BibTeX.c:(.text+0x49): undefined reference to `PL_op'
# BibTeX.c:(.text+0x5e): undefined reference to `PL_curpad'
# BibTeX.c:(.text+0x74): undefined reference to `PL_stack_base'
# BibTeX.c:(.text+0x8c): undefined reference to `PL_stack_base'
# BibTeX.c:(.text+0xbb): undefined reference to `PL_na'
# BibTeX.c:(.text+0xd8): undefined reference to `PL_stack_base'
# BibTeX.c:(.text+0xf1): undefined reference to `PL_stack_base'
...

I guess I need to link -lperl manually? How could I do that?

I tried specifying libperl.a and I then get:

ld -o blib/arch/auto/Text/BibTeX/BibTeX.none xscode/BibTeX.o xscode/btxs_support.o -Lbtparse/src -lbtparse -lperl ~/buildbiber/build/native/perl/libperl.a
# ld: /home/vadimkantorov/buildbiber/build/native/perl/libperl.a(toke.o): undefined reference to symbol 'pow@@GLIBC_2.2.5'
# //lib/x86_64-linux-gnu/libm.so.6: error adding symbols: DSO missing from command line
ld -o blib/arch/auto/Text/BibTeX/BibTeX.none xscode/BibTeX.o xscode/btxs_support.o -Lbtparse/src -lbtparse -lperl ~/buildbiber/build/native/perl/libperl.a -lm -lpthread -lc
# ld: error in btparse/src/libbtparse.so(.eh_frame); no .eh_frame_hdr table will be created.
# ld: warning: cannot find entry symbol _start; defaulting to 0000000000417ce0
ambs commented 3 years ago

Although I would like to help, you are dealing with details I am not aware of.

vadimkantorov commented 3 years ago

I should be able to prepare a repro later in the week

vadimkantorov commented 3 years ago

A more simplified version of this question would be - is it possible to compile Perl with Text::BibTeX in -Dstatic_ext=Text/BibTeX at configure string or with static_ext="Text/BibTeX" in the hintfile.

vadimkantorov commented 3 years ago

Otherwise, do you have a manual building script (without relying on Build.PL / ExtUtils and stuff)? For me that would work and it would be easier than fighting ExtUtils linker options

ambs commented 3 years ago

See if this helps: https://www.cpan.org/modules/by-authors/id/A/AM/AMBS/btparse/

vadimkantorov commented 3 years ago

I guess I'm stuck at trying to get Text::BibTeX working because it's what biber uses. The only non-trivial piece of Text::BibTeX is the XS module. If there's a simple command to build the XS module by calling perl manually, that would work too.

ambs commented 3 years ago

Currently Text::BibTeX bundles a standard C library (btparse) and a Perl module, that has its own library for dynamic loading from Perl. The soname option you refer is being used to link the btparse library. Thus, if you can compile it properly from the link above, then it should be just a matter of understanding how to tweak Text::BibTeX not to compile itself the library.

vadimkantorov commented 3 years ago

Well, by manual compiling and resuming it seems to compile and link. I'm not sure about the scary warnings though.

So compiling btparse itself is not complicated. Then Build.PL still makes a build string with nasty linker flags unsuitable for static builds. If you have an idea how to compile the Perl module without Build.PL in a simpler way, that would work. Or if you managed to build it with make_ext.pl from Perl distribution, that would work as well.