2

On my iMac with Catalina (10.15.6), I installed the augeas brew package and then installed the perl module "Config::Augeas" without issue. On Big Sur, I have not had the same success. After installing the brew package and then doing "cpanm Config::Augeas", I get the following output in the build log:

 27 Building Config-Augeas
 28 cc -I/Users/me/perl5/perlbrew/perls/perl-5.32.1/lib/5.32.1/darwin-2level/CORE -DVERSION="1.000" -DXS_VERSION="1.000" -I/usr/local/Cellar/augeas/1.12.0/include -Wall -Wformat -Werror=format-security -c -fno-common -DPERL_DARWIN -mmacosx-version-min=11.2 -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -DPERL_USE_SAFE_PUTENV -O3 -o lib/Config/Augeas.o lib/Config/Augeas.c
 29 ExtUtils::Mkbootstrap::Mkbootstrap('blib/arch/auto/Config/Augeas/Augeas.bs')
 30 cc -mmacosx-version-min=11.2 -bundle -undefined dynamic_lookup -L/usr/local/lib -fstack-protector-strong -o blib/arch/auto/Config/Augeas/Augeas.bundle lib/Config/Augeas.o -L/usr/local/Cellar/augeas/1.12.0/lib -laugeas
 31 Can't call method "get" on an undefined value at /Users/me/.cpanm/work/1615471944.29922/Config-Augeas-1.000/blib/lib/Config/Augeas.pm line 227.
 32 # Looks like your test exited with 255 just after 2.
 33 t/Config-Augeas.t ...
 34 Dubious, test returned 255 (wstat 65280, 0xff00)
 35 Failed 28/30 subtests
 36
 37 #   Failed test 'Created new Augeas object without backup file'
 38 #   at t/Config-AugeasC.t line 76.
 39 Can't call method "set" on an undefined value at t/Config-AugeasC.t line 78.
 40 # Looks like your test exited with 255 just after 4.
 41 t/Config-AugeasC.t ..
 42 Dubious, test returned 255 (wstat 65280, 0xff00)
 43 Failed 29/32 subtests
 44 Can't stat config-model-edit: No such file or directory
 45  at /Users/me/perl5/perlbrew/perls/perl-5.32.1/lib/site_perl/5.32.1/Test/Pod.pm line 223.
 46 t/pod.t ............. ok

Both machines are running perlbrew (though different versions of perl). I don't think the version of perl is the problem and is more likely that Big Sur made some changes the perl module doesn't like. Any ideas?

StevieD
  • 6,925
  • 2
  • 25
  • 45
  • Were you able to install perl 5.32 on Big Sur using perlbrew without errors? See [macOS Big Sur: Unexpected product version 11.1. How to patch perlbrew?](https://stackoverflow.com/q/65332078/2173773) – Håkon Hægland Mar 11 '21 at 17:47
  • Yes. No problem. – StevieD Mar 11 '21 at 17:59
  • 1
    Just to rule out any problem with perlbrew, I did a clean install of Big Sur on an older mac and tried to install without perlbrew and ran into the same issue. – StevieD Mar 11 '21 at 19:51
  • 1
    Yes I can see the problem here too (macOS 11.2, perlbrew perl 5.32). I can see that the test [t/Config-Augeas.t](https://metacpan.org/source/RAPHINK/Config-Augeas-1.000/t%2FConfig-Augeas.t) fails. It seems that the problem is [line 39](https://metacpan.org/source/RAPHINK/Config-Augeas-1.000/t%2FConfig-Augeas.t#L39) it calls `new()` at [line 116 in Config/Augeas.pm](https://metacpan.org/source/RAPHINK/Config-Augeas-1.000/lib%2FConfig%2FAugeas.pm#L116) ... – Håkon Hægland Mar 11 '21 at 20:02
  • 2
    ... where at [line 142](https://metacpan.org/source/RAPHINK/Config-Augeas-1.000/lib%2FConfig%2FAugeas.pm#L142) it calls `aug_init()` in the XS file [Augeas.xs at line 86](https://metacpan.org/source/RAPHINK/Config-Augeas-1.000/lib%2FConfig%2FAugeas.xs#L86). This functions seems to returns an undefined value. I am looking into what can be the issue. – Håkon Hægland Mar 11 '21 at 20:02
  • Yes, that's what I have determined as well. Unfortunately, I have no knowledge of XS and very little C so I can't get any further on this problem. Thanks for your help. – StevieD Mar 11 '21 at 20:10
  • 1
    If I call `aug_init()` directly from C it works (it does not return NULL). I used [this](https://pastebin.com/LnMszreq) test program, and compiled with ```cc `pkg-config --cflags augeas` `pkg-config --libs augeas` -o anew anew.c```. So my guess is that the problem is related to that perl loads a shared library `libaugeas.dylib` at runtime (indirectly through the perl generated Augeas.bundle) whereas the test C program is compiled with a static library `libaugeas.a`... I am investigating further – Håkon Hægland Mar 12 '21 at 07:55
  • Did a little googling based on what you said in last comment. Found this: https://github.com/ziglang/zig/issues/5715 – StevieD Mar 12 '21 at 13:29
  • 1
    This patch has more details: https://github.com/ziglang/zig/pull/6932 – StevieD Mar 12 '21 at 13:31
  • Interesting, [here](https://stackoverflow.com/q/65383579/2173773) is another one. Not sure if it is related. I need to test more to determine if it actually is the problem.. – Håkon Hægland Mar 12 '21 at 13:37
  • See https://github.com/Perl-Toolchain-Gang/ExtUtils-MakeMaker/issues/381 It seems Ext::MakeMaker had issues with Big Sur. Maybe Module::Build is having the same issue. However, it seems like someone else would have found the issue by now. – StevieD Mar 12 '21 at 14:13
  • 1
    Interestingly, Module::Build hasn't been updated in over a year. Big Sur came out about 9 months ago. So I'm thinking Module::Build is the likely culprit. – StevieD Mar 12 '21 at 14:15
  • 1
    Yes good observation.. but when I test with `ExtUtils::MakeMaker` it still does not work. [Here](https://github.com/hakonhagland/perl-augeas-test) is a link to the test I did. When I run it (`perl p.pl`), `aug_init()` still returns a NULL pointer (on Linux this works fine (it does not return a null pointer)).. So not sure what is going on yet. – Håkon Hægland Mar 12 '21 at 14:33
  • I've been noodling around with this. I noticed line 57 in Build.PL, returns an empty string in Build.PL: my $libxml2_cflags = `pkg-config --cflags libxml-2.0` ; Do you think this might be significant? – StevieD Mar 12 '21 at 14:35
  • Forget my last comment. The command also returned an empty string on catalina. – StevieD Mar 12 '21 at 14:42
  • I have debugged this a little bit more. Problem seems to be related to [this](https://github.com/hercules-team/ruby-augeas/issues/4) issue.. So `aug_init()` calls the wrong `hash_create()` function and therefore fails.. – Håkon Hægland Mar 18 '21 at 23:46
  • 1
    Nice. Thanks. I wish I could help. Learning about linking into system libraries is on my very long "thing to learn about" list. – StevieD Mar 19 '21 at 17:41
  • 1
    Yes this is quite complicated I must admit. I am also learning more as I work with this. Now I think the problem is well described in [this](https://stackoverflow.com/a/65204103/2173773) answer. However, in that answer they used RTLD_DEEPBIND to resolve the symbol conflict. As I understand that flag is not available for `dlopen` on macOS, see [this](https://stackoverflow.com/q/7203161/2173773) question. So I am still looking for a way to resolve the conflict.. – Håkon Hægland Mar 19 '21 at 19:45
  • How goes the battle? Any luck? – StevieD Mar 28 '21 at 21:07
  • This doesn't seem to have been linked yet -- https://rt.cpan.org/Ticket/Display.html?id=134877 – Ether Mar 31 '21 at 17:10

1 Answers1

2

The problem is a bug in libtool which causes dynamic libraries to be compiled with a flat namespace. This again leads to a conflict between two symbols with the same name in the shared libraries libSystem.B.dylib and libfa.1.dylib. Both libraries declare a symbol named hash_create(), however the Perl module needs to resolve the symbol to libfa.1.dylib but libSystem.B.dylib is always loaded before libfa.1.dylib and the wrong version of hash_create() is therefore used.

The problem has been encountered before, see this issue. Further explanations can be found here.

Since the fix to the bug in libtool has not been released as a new version of libtool yet, the problem is not simply solved by upgrading xcode command line tools. Instead you could try to download the libaugeas source and compile from source:

$ brew uninstall augeas
$ wget http://download.augeas.net/augeas-1.12.0.tar.gz
$ cd augeas-1.12.0
$ MACOSX_DEPLOYMENT_TARGET=10.15 ./configure
$ make
$ make install

Note: by specifying MACOSX_DEPLOYMENT_TARGET=10.15 in the above command, we work around the bug and thus do not have to patch configure.

The Perl module should now install fine.

An alternative workaround: you can use dynamic linking (instead of dynamic loading) for libfa.1.dylib. To achieve this I rewrote the module to ExtUtils::MakeMaker instead of Module::Build. Next to install using dynamic linking, you can do:

git clone https://github.com/hakonhagland/Config-Augeas-MM.git
cd https://github.com/hakonhagland/Config-Augeas-MM.git
perl Makefile.PL
make perl
make -f Makefile.aperl inst_perl MAP_TARGET=perl

Note: The last command overwrites your existing perl binary so be careful, see this link for more information.

Now, the module can be tested and installed successfully:

$ make test
"/Users/hakonhaegland/perl5/perlbrew/perls/perl-5.32.0/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- Augeas.bs blib/arch/auto/Config/Augeas/Augeas.bs 644
rm -f blib/arch/auto/Config/Augeas/Augeas.bundle
LD_RUN_PATH="/usr/local/lib" cc  -mmacosx-version-min=11.1 -bundle -undefined dynamic_lookup -L/usr/local/lib -fstack-protector-strong  Augeas.o  -o blib/arch/auto/Config/Augeas/Augeas.bundle  \
       -L/usr/local/lib -laugeas   \

chmod 755 blib/arch/auto/Config/Augeas/Augeas.bundle
PERL_DL_NONLAZY=1 "/Users/hakonhaegland/perl5/perlbrew/perls/perl-5.32.0/bin/perl" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/Config-Augeas.t ... ok
t/Config-AugeasC.t .. ok
t/pod.t ............. skipped: Test::Pod 1.00 required for testing POD
All tests successful.
Files=3, Tests=62,  7 wallclock secs ( 0.04 usr  0.02 sys +  5.71 cusr  0.50 csys =  6.27 CPU)
Result: PASS

$ make install
"/Users/hakonhaegland/perl5/perlbrew/perls/perl-5.32.0/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- Augeas.bs blib/arch/auto/Config/Augeas/Augeas.bs 644
Manifying 1 pod document
Files found in blib/arch: installing files in blib/lib into architecture dependent library tree
Installing /Users/hakonhaegland/perl5/perlbrew/perls/perl-5.32.0/lib/site_perl/5.32.0/darwin-2level/auto/Config/Augeas/extralibs.all
Installing /Users/hakonhaegland/perl5/perlbrew/perls/perl-5.32.0/lib/site_perl/5.32.0/darwin-2level/auto/Config/Augeas/Augeas.a
Installing /Users/hakonhaegland/perl5/perlbrew/perls/perl-5.32.0/lib/site_perl/5.32.0/darwin-2level/auto/Config/Augeas/extralibs.ld
Installing /Users/hakonhaegland/perl5/perlbrew/perls/perl-5.32.0/lib/site_perl/5.32.0/darwin-2level/auto/Config/Augeas/Augeas.bundle
Installing /Users/hakonhaegland/perl5/perlbrew/perls/perl-5.32.0/lib/site_perl/5.32.0/darwin-2level/Config/Augeas.pm
Installing /Users/hakonhaegland/perl5/perlbrew/perls/perl-5.32.0/man/man3/Config::Augeas.3
Appending installation info to /Users/hakonhaegland/perl5/perlbrew/perls/perl-5.32.0/lib/5.32.0/darwin-2level/perllocal.pod

$ perl -MConfig::Augeas -E 'say $INC{"Config/Augeas.pm"}'
/Users/hakonhaegland/perl5/perlbrew/perls/perl-5.32.0/lib/site_perl/5.32.0/darwin-2level/Config/Augeas.pm
Håkon Hægland
  • 39,012
  • 21
  • 81
  • 174
  • Wow, awesome work! I will give this a shot as soon as I get a chance. Might be a few days as I'm bogged down with a bunch of work stuff. – StevieD Mar 29 '21 at 20:34
  • Great! Added a [ticket](https://rt.cpan.org/Ticket/Display.html?id=134877) to notify the author of the issue. – Håkon Hægland Apr 01 '21 at 03:15