Skip to content

Enhance AIX shared library build to use an export List #14334

Open
@KamathForAIX

Description

@KamathForAIX

Hi everyone,

We are building Postgresql using Meson since this will be a good test for Meson in AIX for runtime linking projects.

Till now in AIX, Meson was designed for using compile-time linking only. But now we want to make it build projects using both compile and run-time linking in AIX. [We do have -brtl and -berok within meson but never actually put to use].

Postgres is a project that uses most of the run-time linking concepts, and I want to use that as an example to discuss this issue.

The Postgres sql DB, when wanting to initialize a database, uses binaries [initdb, postgres, pd_ctl, and pg_config] and shared libraries [libpq.a] in AIX. They also use plugins or shared modules in meson, like libpgcommon.so. And this project requires runtime linking.

What makes the build system of Postgres special is that plugins like libpgcommon.so need symbols from the Postgres binary. This means at runtime the linker/loader when using libpgcommon.so need to check the Postgres binary symbols to resolve certain symbols in libpgcommon.so. A binary can also link to a library whose symbols also need to be visible.

In AIX, we need to tell the linker during compile time via an export file what symbols the library it is building exports. For this purpose, we use the -Wl,bE:<path_to_export_file> option in the command. What it does is tells the linker to keep these symbols as exported in the xcoff binary.

This export file is made using the "nm" command followed by the object files used to create a library.

The current version of Meson cannot build Postgres because it does not build the export file for libraries. Hence the berok option will allow the build to be successful, but then the database will crash since it simply cannot resolve symbols.

Through this issue, I would like to enhance Meson to create export files in AIX to make runtime linking possible.

I have solved this problem and am raising a PR for the community to check.

As always, AIX likes using Meson, and we are open to further optimal ways to build.

I do see a symbol extractor code written in the scripts folder and would like to use that.

A sample example for the fix is as shown below:

<build.ninja file>

rule AIX_LINKER
 command = ar -q -v $out $in && rm -f $in
 description = Archiving AIX shared library

rule Export_List_AIX_Object
 command = /usr/bin/ld -r -o $out $in
 description = Export file object creation for AIX

rule AIX_SHSYM
 command = /meson/install/opt/freeware/bin/meson --internal symbolextractor /glib/aix $in $IMPLIB $out $CROSS
 description = Generating AIX symbol file $out
 restat = 1

build glib/tests/getpwuid-preload.so_SUBSYS.o: Export_List_AIX_Object glib/tests/getpwuid-preload.so.p/getpwuid-preload.c.o
 IMPLIB = glib/tests/getpwuid-preload.a

build glib/tests/getpwuid-preload.so.exp: AIX_SHSYM glib/tests/getpwuid-preload.so_SUBSYS.o
 IMPLIB = glib/tests/getpwuid-preload.a

build glib/tests/getpwuid-preload.so: c_LINKER glib/tests/getpwuid-preload.so.p/getpwuid-preload.c.o glib/tests/getpwuid-preload.so.exp
 LINK_ARGS = -Wl,-bernotok -Wl,-bnoipath -Wl,-bbigtoc -shared -fPIC -Wl,-bE:glib/tests/getpwuid-preload.so.exp -Wl,-blibpath:/opt/freeware/lib64:/opt/freeware/lib:/usr/lib:/lib -Wl,-blibpath:/opt/freeware/lib/gcc/p
owerpc-ibm-aix7.2.0.0/10/pthread/ppc64:/opt/freeware/lib/pthread/ppc64:/opt/freeware/lib/gcc/powerpc-ibm-aix7.2.0.0/10:/opt/freeware/lib:/lib:/usr/lib

build glib/tests/getpwuid-preload.a: AIX_LINKER glib/tests/getpwuid-preload.so

The commands

[468/1502] /usr/bin/ld -r -o glib/tests/getpwuid-preload.so_SUBSYS.o glib/tests/getpwuid-preload.so.p/getpwuid-preload.c.o
[477/1502] /meson/install/opt/freeware/bin/meson --internal symbolextractor /glib/aix glib/tests/getpwuid-preload.so_SUBSYS.o glib/tests/getpwuid-preload.a glib/tests/getpwuid-preload.so.exp 
Symbols are written to  glib/tests/getpwuid-preload.so.exp

[497/1502] gcc -pthread -maix64  -o glib/tests/getpwuid-preload.so glib/tests/getpwuid-preload.so.p/getpwuid-preload.c.o glib/tests/getpwuid-preload.so.exp -Wl,-bernotok -Wl,-bnoipath -Wl,-bbigtoc -shared -fPIC -Wl,-bE:glib/tests/getpwuid-preload.so.exp -Wl,-blibpath:/opt/freeware/lib64:/opt/freeware/lib:/usr/lib:/lib -Wl,-blibpath:/opt/freeware/lib/gcc/powerpc-ibm-aix7.2.0.0/10/pthread/ppc64:/opt/freeware/lib/pthread/ppc64:/opt/freeware/lib/gcc/powerpc-ibm-aix7.2.0.0/10:/opt/freeware/lib:/lib:/usr/lib

[999/1502] ar -q -v glib/tests/getpwuid-preload.a glib/tests/getpwuid-preload.so && rm -f glib/tests/getpwuid-preload.so
ar: Creating an archive file glib/tests/getpwuid-preload.a.
q - glib/tests/getpwuid-preload.so

This is what we want to achieve. I am open to ideas :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions