Skip to content

Commit f4d19db

Browse files
KamathForAIXeli-schwartz
authored andcommitted
Use target.aix_so_archive to decide to archive shared library in AIX
Previously, AIX support was updated to archive shared libraries per AIX platform conventions, which expect .a files that contain .so files. This is usually correct, but an edge case occurs for loadable plugins, e.g. what meson creates for `shared_module()`. A notable example is python extensions (SciPy, for example). These should *not* be archived, because the .so file itself needs to be loaded as a plugin. For example, SciPy fails to import in the python interpreter. Handle this by differentiating between plugins and regular libraries, and only archiving when safe to do so. Fixes mesonbuild#12219
1 parent ce691f8 commit f4d19db

4 files changed

Lines changed: 15 additions & 9 deletions

File tree

‎mesonbuild/backend/backends.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,9 @@ def get_target_filename_for_linking(self, target: T.Union[build.Target, build.Cu
355355
# On all other platforms, we link to the library directly.
356356
if isinstance(target, build.SharedLibrary):
357357
link_lib = target.get_import_filename() or target.get_filename()
358+
# In AIX, if we archive .so, the blibpath must link to archived shared library otherwise to the .so file.
359+
if mesonlib.is_aix() and target.aix_so_archive:
360+
link_lib = re.sub('[.][a]([.]?([0-9]+))*([.]?([a-z]+))*', '.a', link_lib.replace('.so', '.a'))
358361
return os.path.join(self.get_target_dir(target), link_lib)
359362
elif isinstance(target, build.StaticLibrary):
360363
return os.path.join(self.get_target_dir(target), target.get_filename())

‎mesonbuild/backend/ninjabackend.py‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,8 +1060,9 @@ def generate_target(self, target):
10601060
#In AIX, we archive shared libraries. If the instance is a shared library, we add a command to archive the shared library
10611061
#object and create the build element.
10621062
if isinstance(target, build.SharedLibrary) and self.environment.machines[target.for_machine].is_aix():
1063-
elem = NinjaBuildElement(self.all_outputs, linker.get_archive_name(outname), 'AIX_LINKER', [outname])
1064-
self.add_build(elem)
1063+
if target.aix_so_archive:
1064+
elem = NinjaBuildElement(self.all_outputs, linker.get_archive_name(outname), 'AIX_LINKER', [outname])
1065+
self.add_build(elem)
10651066

10661067
def should_use_dyndeps_for_target(self, target: 'build.BuildTarget') -> bool:
10671068
if mesonlib.version_compare(self.ninja_version, '<1.10.0'):
@@ -3457,11 +3458,6 @@ def generate_link(self, target: build.BuildTarget, outname, obj_list, linker: T.
34573458
else:
34583459
dependencies = target.get_dependencies()
34593460
internal = self.build_target_link_arguments(linker, dependencies)
3460-
#In AIX since shared libraries are archived the dependencies must
3461-
#depend on .a file with the .so and not directly on the .so file.
3462-
if self.environment.machines[target.for_machine].is_aix():
3463-
for i, val in enumerate(internal):
3464-
internal[i] = linker.get_archive_name(val)
34653461
commands += internal
34663462
# Only non-static built targets need link args and link dependencies
34673463
if not isinstance(target, build.StaticLibrary):
@@ -3667,7 +3663,7 @@ def generate_ending(self) -> None:
36673663
# Add the first output of each target to the 'all' target so that
36683664
# they are all built
36693665
#Add archive file if shared library in AIX for build all.
3670-
if isinstance(t, build.SharedLibrary):
3666+
if isinstance(t, build.SharedLibrary) and t.aix_so_archive:
36713667
if self.environment.machines[t.for_machine].is_aix():
36723668
linker, stdlib_args = self.determine_linker_and_stdlib_args(t)
36733669
t.get_outputs()[0] = linker.get_archive_name(t.get_outputs()[0])

‎mesonbuild/build.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2171,6 +2171,9 @@ class SharedLibrary(BuildTarget):
21712171

21722172
typename = 'shared library'
21732173

2174+
# Used by AIX to decide whether to archive shared library or not.
2175+
aix_so_archive = True
2176+
21742177
def __init__(
21752178
self,
21762179
name: str,
@@ -2436,6 +2439,9 @@ class SharedModule(SharedLibrary):
24362439

24372440
typename = 'shared module'
24382441

2442+
# Used by AIX to not archive shared library for dlopen mechanism
2443+
aix_so_archive = False
2444+
24392445
def __init__(
24402446
self,
24412447
name: str,

‎mesonbuild/minstall.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,8 +722,9 @@ def install_targets(self, d: InstallData, dm: DirMaker, destdir: str, fullprefix
722722
# In AIX, we archive our shared libraries. When we install any package in AIX we need to
723723
# install the archive in which the shared library exists. The below code does the same.
724724
# We change the .so files having lt_version or so_version to archive file install.
725+
# If .so does not exist then it means it is in the archive. Otherwise it is a .so that exists.
725726
if is_aix():
726-
if '.so' in t.fname:
727+
if not os.path.exists(t.fname) and '.so' in t.fname:
727728
t.fname = re.sub('[.][a]([.]?([0-9]+))*([.]?([a-z]+))*', '.a', t.fname.replace('.so', '.a'))
728729
if not self.should_install(t):
729730
continue

0 commit comments

Comments
 (0)