Skip to content

Commit fa99485

Browse files
eli-schwartznirbheek
authored andcommitted
fix linker regression for compilers that don't accept LDFLAGS directly
e.g. ldc -- the compiler needs to process args before consuming them. Fixes #10693
1 parent c3ab7ed commit fa99485

File tree

7 files changed

+34
-14
lines changed

7 files changed

+34
-14
lines changed

mesonbuild/compilers/compilers.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,10 +690,14 @@ def has_function(self, funcname: str, prefix: str, env: 'Environment', *,
690690
"""
691691
raise EnvironmentException('Language %s does not support function checks.' % self.get_display_language())
692692

693-
def unix_args_to_native(self, args: T.List[str]) -> T.List[str]:
693+
@classmethod
694+
def _unix_args_to_native(cls, args: T.List[str], info: 'MachineInfo') -> T.List[str]:
694695
"Always returns a copy that can be independently mutated"
695696
return args.copy()
696697

698+
def unix_args_to_native(self, args: T.List[str]) -> T.List[str]:
699+
return self._unix_args_to_native(args, self.info)
700+
697701
@classmethod
698702
def native_args_to_unix(cls, args: T.List[str]) -> T.List[str]:
699703
"Always returns a copy that can be independently mutated"

mesonbuild/compilers/d.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@ def build_rpath_args(self, env: 'Environment', build_dir: str, from_dir: str,
281281
return super().build_rpath_args(
282282
env, build_dir, from_dir, rpath_paths, build_rpath, install_rpath)
283283

284-
def _translate_args_to_nongnu(self, args: T.List[str]) -> T.List[str]:
284+
@classmethod
285+
def _translate_args_to_nongnu(cls, args: T.List[str], info: 'MachineInfo', link_id: str) -> T.List[str]:
285286
# Translate common arguments to flags the LDC/DMD compilers
286287
# can understand.
287288
# The flags might have been added by pkg-config files,
@@ -296,10 +297,10 @@ def _translate_args_to_nongnu(self, args: T.List[str]) -> T.List[str]:
296297
for arg in args:
297298
# Translate OS specific arguments first.
298299
osargs = [] # type: T.List[str]
299-
if self.info.is_windows():
300-
osargs = self.translate_arg_to_windows(arg)
301-
elif self.info.is_darwin():
302-
osargs = self._translate_arg_to_osx(arg)
300+
if info.is_windows():
301+
osargs = cls.translate_arg_to_windows(arg)
302+
elif info.is_darwin():
303+
osargs = cls._translate_arg_to_osx(arg)
303304
if osargs:
304305
dcargs.extend(osargs)
305306
continue
@@ -384,7 +385,7 @@ def _translate_args_to_nongnu(self, args: T.List[str]) -> T.List[str]:
384385
continue
385386

386387
# linker flag such as -L=/DEBUG must pass through
387-
if self.linker.id == 'link' and self.info.is_windows() and suffix.startswith('/'):
388+
if info.is_windows() and link_id == 'link' and suffix.startswith('/'):
388389
dcargs.append(arg)
389390
continue
390391

@@ -438,6 +439,10 @@ def _translate_arg_to_osx(cls, arg: str) -> T.List[str]:
438439
args.append('-L=' + arg)
439440
return args
440441

442+
@classmethod
443+
def _unix_args_to_native(cls, args: T.List[str], info: 'MachineInfo', link_id: str = '') -> T.List[str]:
444+
return cls._translate_args_to_nongnu(args, info, link_id)
445+
441446
def get_debug_args(self, is_debug: bool) -> T.List[str]:
442447
ddebug_args = []
443448
if is_debug:
@@ -897,7 +902,7 @@ def get_crt_link_args(self, crt_val: str, buildtype: str) -> T.List[str]:
897902
return self._get_crt_args(crt_val, buildtype)
898903

899904
def unix_args_to_native(self, args: T.List[str]) -> T.List[str]:
900-
return self._translate_args_to_nongnu(args)
905+
return self._unix_args_to_native(args, self.info, self.linker.id)
901906

902907
def get_optimization_args(self, optimization_level: str) -> T.List[str]:
903908
return ldc_optimization_args[optimization_level]
@@ -986,7 +991,7 @@ def get_crt_compile_args(self, crt_val: str, buildtype: str) -> T.List[str]:
986991
return self._get_crt_args(crt_val, buildtype)
987992

988993
def unix_args_to_native(self, args: T.List[str]) -> T.List[str]:
989-
return self._translate_args_to_nongnu(args)
994+
return self._unix_args_to_native(args, self.info, self.linker.id)
990995

991996
def get_optimization_args(self, optimization_level: str) -> T.List[str]:
992997
return dmd_optimization_args[optimization_level]

mesonbuild/compilers/mixins/ccrx.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
from __future__ import annotations
1415

1516
"""Representations specific to the Renesas CC-RX compiler family."""
1617

@@ -20,6 +21,7 @@
2021
from ...mesonlib import EnvironmentException
2122

2223
if T.TYPE_CHECKING:
24+
from ...envconfig import MachineInfo
2325
from ...environment import Environment
2426
from ...compilers.compilers import Compiler
2527
else:
@@ -105,7 +107,7 @@ def get_debug_args(self, is_debug: bool) -> T.List[str]:
105107
return ccrx_debug_args[is_debug]
106108

107109
@classmethod
108-
def unix_args_to_native(cls, args: T.List[str]) -> T.List[str]:
110+
def _unix_args_to_native(cls, args: T.List[str], info: 'MachineInfo') -> T.List[str]:
109111
result = []
110112
for i in args:
111113
if i.startswith('-D'):

mesonbuild/compilers/mixins/compcert.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
from __future__ import annotations
1415

1516
"""Representations specific to the CompCert C compiler family."""
1617

@@ -19,6 +20,7 @@
1920
import typing as T
2021

2122
if T.TYPE_CHECKING:
23+
from envconfig import MachineInfo
2224
from ...environment import Environment
2325
from ...compilers.compilers import Compiler
2426
else:
@@ -87,7 +89,8 @@ def get_pch_suffix(self) -> str:
8789
def get_pch_use_args(self, pch_dir: str, header: str) -> T.List[str]:
8890
return []
8991

90-
def unix_args_to_native(self, args: T.List[str]) -> T.List[str]:
92+
@classmethod
93+
def _unix_args_to_native(cls, args: T.List[str], info: 'MachineInfo') -> T.List[str]:
9194
"Always returns a copy that can be independently mutated"
9295
patched_args = [] # type: T.List[str]
9396
for arg in args:

mesonbuild/compilers/mixins/ti.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
from __future__ import annotations
1415

1516
"""Representations specific to the Texas Instruments compiler family."""
1617

@@ -20,6 +21,7 @@
2021
from ...mesonlib import EnvironmentException
2122

2223
if T.TYPE_CHECKING:
24+
from ...envconfig import MachineInfo
2325
from ...environment import Environment
2426
from ...compilers.compilers import Compiler
2527
else:
@@ -120,7 +122,7 @@ def get_include_args(self, path: str, is_system: bool) -> T.List[str]:
120122
return ['-I=' + path]
121123

122124
@classmethod
123-
def unix_args_to_native(cls, args: T.List[str]) -> T.List[str]:
125+
def _unix_args_to_native(cls, args: T.List[str], info: 'MachineInfo') -> T.List[str]:
124126
result = []
125127
for i in args:
126128
if i.startswith('-D'):

mesonbuild/compilers/mixins/xc16.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
from __future__ import annotations
1415

1516
"""Representations specific to the Microchip XC16 C compiler family."""
1617

@@ -20,6 +21,7 @@
2021
from ...mesonlib import EnvironmentException
2122

2223
if T.TYPE_CHECKING:
24+
from ...envconfig import MachineInfo
2325
from ...environment import Environment
2426
from ...compilers.compilers import Compiler
2527
else:
@@ -104,7 +106,7 @@ def get_debug_args(self, is_debug: bool) -> T.List[str]:
104106
return xc16_debug_args[is_debug]
105107

106108
@classmethod
107-
def unix_args_to_native(cls, args: T.List[str]) -> T.List[str]:
109+
def _unix_args_to_native(cls, args: T.List[str], info: 'MachineInfo') -> T.List[str]:
108110
result = []
109111
for i in args:
110112
if i.startswith('-D'):

mesonbuild/linkers/detect.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ def guess_nix_linker(env: 'Environment', compiler: T.List[str], comp_class: T.Ty
140140
"""
141141
env.coredata.add_lang_args(comp_class.language, comp_class, for_machine, env)
142142
extra_args = extra_args or []
143-
extra_args += env.coredata.get_external_link_args(for_machine, comp_class.language)
143+
144+
ldflags = env.coredata.get_external_link_args(for_machine, comp_class.language)
145+
extra_args += comp_class._unix_args_to_native(ldflags, env.machines[for_machine])
144146

145147
if isinstance(comp_class.LINKER_PREFIX, str):
146148
check_args = [comp_class.LINKER_PREFIX + '--version'] + extra_args

0 commit comments

Comments
 (0)