Skip to content

Commit 55f0236

Browse files
committed
compiler: Add shared object versioning to pgcc
1 parent 77c6edc commit 55f0236

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

devito/arch/compiler.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from functools import partial
22
from hashlib import sha1
3+
from itertools import repeat, filterfalse
34
from os import environ, path, makedirs
45
from packaging.version import Version
56
from subprocess import (DEVNULL, PIPE, CalledProcessError, check_output,
@@ -666,6 +667,30 @@ def __lookup_cmds__(self):
666667
self.MPICC = 'mpic++'
667668
self.MPICXX = 'mpicxx'
668669

670+
def add_libraries(self, libs):
671+
# Urgh...
672+
# PGIComiler inherits from Compiler inherits from GCCToolchain in codepy
673+
# GCC supports linking versioned shared objects with the syntax
674+
# `gcc -L/path/to/versioned/lib -l:libfoo.so.2.0 ...`
675+
# But this syntax is not supported by the Portland (or Nvidia) compiler.
676+
# Nor does codepy.GCCToolchain understand that linking to versioned objects
677+
# is a thing that someone might want to do
678+
#
679+
# Since this is just linking information, we can just tell the linker
680+
# (which we invoke using the compiler and the `-Wl,-options` syntax) to
681+
# go and look in all of the directories we have provided thus far and
682+
# the linker supports the syntax:
683+
# `ld -L/path/to/versioned/lib -l:libfoo.so.2.0 ...`
684+
# Note: It would be nicer to just look in the one _relevant_ lib dir!
685+
new = as_list(libs)
686+
versioned = filter(lambda s: s.startswith(':'), new)
687+
versioned = map(lambda s: s.removeprefix(':'), versioned)
688+
self.add_ldflags([
689+
f'-Wl,-L{",-L".join(map(str, self.library_dirs))},-l:{soname}'
690+
for soname in versioned
691+
])
692+
super().add_libraries(filterfalse(lambda s: s.startswith(':'), new))
693+
669694

670695
class NvidiaCompiler(PGICompiler):
671696

devito/passes/iet/engine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ def apply(self, func, **kwargs):
147147
try:
148148
compiler = kwargs['compiler']
149149
compiler.add_include_dirs(as_tuple(metadata.get('include_dirs')))
150-
compiler.add_libraries(as_tuple(metadata.get('libs')))
151150
compiler.add_library_dirs(as_tuple(metadata.get('lib_dirs')),
152151
rpath=metadata.get('rpath', False))
152+
compiler.add_libraries(as_tuple(metadata.get('libs')))
153153
except KeyError:
154154
pass
155155

0 commit comments

Comments
 (0)