Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Test extern'd globals on MacOS with the Apple Archiver #11945

Merged
merged 2 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion mesonbuild/backend/ninjabackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -2350,7 +2350,7 @@ def generate_static_link_rules(self):
if static_linker is None:
continue
rule = 'STATIC_LINKER{}'.format(self.get_rule_suffix(for_machine))
cmdlist = []
cmdlist: T.List[T.Union[str, NinjaCommandArg]] = []
args = ['$in']
# FIXME: Must normalize file names with pathlib.Path before writing
# them out to fix this properly on Windows. See:
Expand All @@ -2364,6 +2364,17 @@ def generate_static_link_rules(self):
cmdlist += static_linker.get_exelist()
cmdlist += ['$LINK_ARGS']
cmdlist += NinjaCommandArg.list(static_linker.get_output_args('$out'), Quoting.none)
# The default ar on MacOS (at least through version 12), does not
# add extern'd variables to the symbol table by default, and
# requires that apple's ranlib be called with a special flag
# instead after linking
if static_linker.id == 'applear':
# This is a bit of a hack, but we assume that that we won't need
# an rspfile on MacOS, otherwise the arguments are passed to
# ranlib, not to ar
cmdlist.extend(args)
args = []
cmdlist.extend(['&&', 'ranlib', '-c', '$out'])
description = 'Linking static target $out'
if num_pools > 0:
pool = 'pool = link_pool'
Expand Down
4 changes: 4 additions & 0 deletions mesonbuild/linkers/linkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ class VisualStudioLinker(VisualStudioLikeLinker, StaticLinker):

"""Microsoft's lib static linker."""

id = 'lib'

def __init__(self, exelist: T.List[str], machine: str):
StaticLinker.__init__(self, exelist)
VisualStudioLikeLinker.__init__(self, machine)
Expand All @@ -358,6 +360,8 @@ class IntelVisualStudioLinker(VisualStudioLikeLinker, StaticLinker):

"""Intel's xilib static linker."""

id = 'xilib'

def __init__(self, exelist: T.List[str], machine: str):
StaticLinker.__init__(self, exelist)
VisualStudioLikeLinker.__init__(self, machine)
Expand Down
9 changes: 9 additions & 0 deletions test cases/osx/9 global variable ar/libfile.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Source: https://lists.gnu.org/archive/html/libtool/2002-07/msg00025.html

#include <stdio.h>

extern int l2;
void l1(void)
{
printf("l1 %d\n", l2);
}
7 changes: 7 additions & 0 deletions test cases/osx/9 global variable ar/libfile2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Source: https://lists.gnu.org/archive/html/libtool/2002-07/msg00025.html

int l2;
void l2_func(void)
{
l2 = 77;
}
6 changes: 6 additions & 0 deletions test cases/osx/9 global variable ar/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Source: https://lists.gnu.org/archive/html/libtool/2002-07/msg00025.html

project('global variable test', 'c')

lib = static_library('mylib', 'libfile.c', 'libfile2.c')
test('global variable', executable('prog', 'prog.c', link_with: lib))
2 changes: 2 additions & 0 deletions test cases/osx/9 global variable ar/nativefile.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[binaries]
ar = 'ar'
7 changes: 7 additions & 0 deletions test cases/osx/9 global variable ar/prog.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Source: https://lists.gnu.org/archive/html/libtool/2002-07/msg00025.html

extern void l1(void);
int main(void)
{
l1();
}