[vim/vim] Dynamic loading broken with Perl 5.36 (Issue #10512)

181 views
Skip to first unread message

Evangelos Foutras

unread,
Jun 2, 2022, 12:29:38 PM6/2/22
to vim/vim, Subscribed

Steps to reproduce

  1. Build vim with --enable-perlinterp=dynamic against Perl 5.36
  2. Inspect the vim binary with readelf -d revealing a DT_NEEDED entry for libperl.so

Expected behaviour

The vim binary should not be linked to libperl so it can be dynamically loaded at runtime.

Comparing the readelf -Ws vim | grep UND output between Perl 5.34 and 5.36 shows a new symbol reference: PL_current_context

Version of Vim

8.2.5046

Environment

Arch Linux x86_64

Logs and stack traces

No response


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/10512@github.com>

Bram Moolenaar

unread,
Jun 2, 2022, 1:26:10 PM6/2/22
to vim/vim, Subscribed


> ### Steps to reproduce
>
> 1. Build vim with `--enable-perlinterp=dynamic` against Perl 5.36
> 2. Inspect the vim binary with `readelf -d` revealing a DT_NEEDED entry for libperl.so
>
> ### Expected behaviour

>
> The vim binary should not be linked to libperl so it can be dynamically loaded at runtime.
>
> Comparing the `readelf -Ws vim | grep UND` output between Perl 5.34 and 5.36 shows a new symbol reference: `PL_current_context`
>
> ### Version of Vim
>
> 8.2.5046
>
> ### Environment
>
> Arch Linux x86_64

My Ubuntu system has Perl 5.34 and it looks OK. Is this a problem
specific for Perl 5.36 or for Arch Linux?

--
WOMAN: Well, 'ow did you become king then?
ARTHUR: The Lady of the Lake, [angels sing] her arm clad in the purest
shimmering samite, held aloft Excalibur from the bosom of the water
signifying by Divine Providence that I, Arthur, was to carry
Excalibur. [singing stops] That is why I am your king!
The Quest for the Holy Grail (Monty Python)

/// Bram Moolenaar -- ***@***.*** -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/10512/1145116296@github.com>

Evangelos Foutras

unread,
Jun 2, 2022, 1:38:13 PM6/2/22
to vim/vim, Subscribed

Is this a problem specific for Perl 5.36 or for Arch Linux?

It appears to be specific to Perl 5.36 because it was fine with Perl 5.34 on Arch Linux too.

As far as I can tell, the PL_current_context symbol is new in Perl 5.36 and was introduced by Perl/perl5@3683a9e.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/10512/1145127571@github.com>

Bram Moolenaar

unread,
Jun 2, 2022, 3:03:15 PM6/2/22
to vim/vim, Subscribed

Vim does not use PL_current_context, I'm not sure if we can do anything about this.
You could ask the Perl maintainers about this.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/10512/1145211945@github.com>

Evangelos Foutras

unread,
Jun 2, 2022, 4:03:06 PM6/2/22
to vim/vim, Subscribed

As far as I can see, including perl.h brings in Perl's thread.h which in turn contains a reference to PL_current_context.

A code comment added as part of Perl/perl5@3683a9e has this to say about it:

 * This is not a regular "global" in that we don't know whether it needs to
 * exist until we include threads.h, and we don't want it as part of any
 * global struct (if that or something similar is re-introduced.

This feels similar to how previous major Perl upgrades have required changes in Vim to accommodate them, even though Vim's code didn't change in regard to its Perl usage.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/10512/1145289282@github.com>

Evangelos Foutras

unread,
Jun 2, 2022, 5:27:25 PM6/2/22
to vim/vim, Subscribed

This following change prevents Vim from linking to libperl (without breaking the test suite):

diff --git a/src/if_perl.xs b/src/if_perl.xs
index 1afb1d4cf..8aab5337b 100644
--- a/src/if_perl.xs
+++ b/src/if_perl.xs
@@ -168,6 +168,10 @@ typedef int XSUBADDR_t;
 typedef int perl_key;
 # endif
 
+#if defined(USE_ITHREADS) && defined(PERL_THREAD_LOCAL)
+PERL_THREAD_LOCAL void *PL_current_context;
+#endif
+
 # ifndef MSWIN
 #  include <dlfcn.h>
 #  define HANDLE void*

However, I am not sure if this is the correct approach or how it interacts with the same symbol in libperl:

$ readelf -Ws src/vim | grep PL_current_context
  1184: 0000000000000000     8 TLS     GLOBAL DEFAULT   17 PL_current_context

$ readelf -Ws /usr/lib/perl5/5.36/core_perl/CORE/libperl.so | grep PL_current_context
  1452: 0000000000000000     8 TLS     GLOBAL DEFAULT   15 PL_current_context


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/10512/1145358103@github.com>

Bram Moolenaar

unread,
Jun 3, 2022, 6:09:39 AM6/3/22
to vim/vim, Subscribed


> As far as I can see, including `perl.h` brings in Perl's `thread.h` which in turn contains a reference to `PL_current_context`.
>
> A code comment added as part of https://github.com/Perl/perl5/commit/3683a9ee5ad61f8cb5eac30e61b4936bd0445bdb has this to say about it:

> ```
> * This is not a regular "global" in that we don't know whether it needs to
> * exist until we include threads.h, and we don't want it as part of any
> * global struct (if that or something similar is re-introduced.
> ```
>
> This feels similar to how previous major Perl upgrades have required
> changes in Vim to accommodate them, even though Vim's code didn't
> change in regard to its Perl usage.

Perhaps this is similar to how PL_thr_key is handled?

--
Q: How does a UNIX Guru pick up a girl?
A: look; grep; which; eval; nice; uname; talk; date;


/// Bram Moolenaar -- ***@***.*** -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/10512/1145810207@github.com>

Bram Moolenaar

unread,
Jun 3, 2022, 6:09:41 AM6/3/22
to vim/vim, Subscribed


> This following change prevents Vim from linking to libperl (without breaking the test suite):
>
> ```diff
> diff --git a/src/if_perl.xs b/src/if_perl.xs
> index 1afb1d4cf..8aab5337b 100644
> --- a/src/if_perl.xs
> +++ b/src/if_perl.xs
> @@ -168,6 +168,10 @@ typedef int XSUBADDR_t;
> typedef int perl_key;
> # endif
>
> +#if defined(USE_ITHREADS) && defined(PERL_THREAD_LOCAL)
> +PERL_THREAD_LOCAL void *PL_current_context;
> +#endif
> +
> # ifndef MSWIN
> # include <dlfcn.h>
> # define HANDLE void*
> ```
>
> However, I am not sure if this is the correct approach or how it interacts with the same symbol in libperl:
>
> ```
> $ readelf -Ws src/vim | grep PL_current_context
> 1184: 0000000000000000 8 TLS GLOBAL DEFAULT 17 PL_current_context
>
> $ readelf -Ws /usr/lib/perl5/5.36/core_perl/CORE/libperl.so | grep PL_current_context
> 1452: 0000000000000000 8 TLS GLOBAL DEFAULT 15 PL_current_context
> ```

This will create a duplicate variable, that can't work properly.

--
Courtroom Quote #19:
Q: Doctor, how many autopsies have you performed on dead people?
A: All my autopsies have been performed on dead people.


/// Bram Moolenaar -- ***@***.*** -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/10512/1145810225@github.com>

Emil Velikov

unread,
Aug 17, 2023, 1:01:40 PM8/17/23
to vim/vim, Subscribed

At a face value, resolving this is trivial - just add the extra symbol to be dlsym-ed (just like PL_thr_key) can call it a day. Although looking deeper things are a bit more convoluted:

The symbol is annotated as _Thread_local and fetched once in the early startup stage. Then the symbol is used with perl when spawning threads and boom. If the created was created first and then the symbol was fetched the standard runtime would provide separate truly thread-local symbols.

So there's on obvious solution for this atm ... at least not without some proper digging.

Although this bug has highlighted another bug - when --enable-perlintero=dynamic is used the link command is not updated to exclude the library - filed as #12827


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/10512/1682651077@github.com>

Christian Brabandt

unread,
Aug 17, 2023, 2:11:33 PM8/17/23
to vim/vim, Subscribed

just add the extra symbol to be dlsym-ed (just like PL_thr_key) can call it a day

can you create a PR for this please 🙏 ?


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/10512/1682744046@github.com>

K.Takata

unread,
Aug 18, 2023, 9:56:42 AM8/18/23
to vim/vim, Subscribed

This should have been fixed in 9.0.1700. Closing.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/10512/1683960087@github.com>

K.Takata

unread,
Aug 18, 2023, 9:56:44 AM8/18/23
to vim/vim, Subscribed

Closed #10512 as completed.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issue/10512/issue_event/10130329216@github.com>

Emil Velikov

unread,
Aug 18, 2023, 10:44:55 AM8/18/23
to vim/vim, Subscribed

Cannot see the new symbol being added to the codebase so I'm not sure how that can be fixed.

Regardless, just gave this a try and it's still broken - see objdump -CtT .../vim | grep PL_current_context


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/10512/1684026117@github.com>

Emil Velikov

unread,
Aug 18, 2023, 10:46:19 AM8/18/23
to vim/vim, Subscribed

As mentioned in my earlier reply - fixing this isn't particularly straightforward, since the symbol is annotated as _Thread_local.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/10512/1684027990@github.com>

Reply all
Reply to author
Forward
0 new messages