ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: "Michal Vlasák" <lahcim8@gmail.com>
To: "mailing list for ConTeXt users" <ntg-context@ntg.nl>
Subject: [NTG-context] Re: Building luametatex with Lua symbols exposed
Date: Sat, 02 Sep 2023 23:43:30 +0200	[thread overview]
Message-ID: <CV8RCT09TOLP.D3STOAQ1DDGS@phobos> (raw)
In-Reply-To: <CAKyqqab5nnm8bY=vHRbfgWp+8ut0dgGatdN7_-470O4MC+7W_w@mail.gmail.com>

On Wed Aug 30, 2023 at 6:23 PM CEST, Jairo A. del Rio wrote:
> Hi, beloved list. Since sources are in the distribution, I've tried
> compiling luametatex by setting LMT_STRIP in CMakeLists.txt to 0, yet the
> resulting binary still warns about undefined symbols, such as lua_gettop,
> when an external library is loaded in Lua. Any ideas on how to solve it?

Hi Jairo,

you need to expose _dynamic_ symbols in your luametatex binary. If you
are using Linux, just adding the following to the CMake invocation line
should work:

    -DCMAKE_EXECUTABLE_ENABLE_EXPORTS=1

For example, I compiled with:

    cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXECUTABLE_ENABLE_EXPORTS=1
    cmake --build build -j10

You can check the difference in dynamic symobls with:

    readelf --dyn-syms build/luametatex


Note, that while this approach doesn't require any modification to
luametatex's source files, it does export _all_ symbols, which makes
binaries bigger, and symbol resolution slower. It also exports also
symbols that are not intended to be used by external modules, like
"tex_get_x_token".

Back when luametatex source code wasn't available, I created a demo
which showed how to build a "luametatex like application" (i.e.
executable with Lua statically linked in), with exported dynamic
symbols, working with CMake on both Unix and Windows. It might interest
you:

    https://github.com/vlasakm/lua-demo

To support Windows in the case of luametatex, "#define LUA_BUILD_AS_DLL"
would need to be added when compiling Lua.

The problem with any module is, that you want to compile against exactly
the same Lua headers as the ones in luametatex, and with similar flags.
That is why the demo hosts everything in one CMake setup, but since
Lua's API hopefully doesn't change in the 5.4 series, you are probably
fine even with separate compilation.

IIRC stripping (LMT_STRIP) applies only to static symbols ("symbols")
and not the dynamic ones ("dynamic symbols"), and thus should be
irrelevant.

It seems that people had similar issues before:

   https://www.mail-archive.com/ntg-context@ntg.nl/msg97764.html
   https://www.mail-archive.com/ntg-context@ntg.nl/msg98184.html

I think it would be nice to support this "by default", but in that case,
the binary size would have to be addressed, and only the "supported"
public API of luametatex actually exposed. Support of this could also be
behind a compile time switch, but I am not sure how useful would that
be.

Michal
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : https://contextgarden.net
___________________________________________________________________________________

      reply	other threads:[~2023-09-02 21:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-30 16:23 [NTG-context] " Jairo A. del Rio
2023-09-02 21:43 ` Michal Vlasák [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CV8RCT09TOLP.D3STOAQ1DDGS@phobos \
    --to=lahcim8@gmail.com \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).