CompilerArgs: Put start/end-group around shared libs too

Closes https://github.com/mesonbuild/meson/issues/2096
pull/2107/head
Nirbheek Chauhan 8 years ago committed by Jussi Pakkanen
parent 5f6add79e0
commit b3d048e93a
  1. 23
      mesonbuild/compilers/compilers.py
  2. 8
      test cases/common/153 recursive linking/edge-cases/libsto.c
  3. 9
      test cases/common/153 recursive linking/edge-cases/meson.build
  4. 16
      test cases/common/153 recursive linking/edge-cases/shstmain.c
  5. 7
      test cases/common/153 recursive linking/edge-cases/stobuilt.c
  6. 16
      test cases/common/153 recursive linking/edge-cases/stomain.c
  7. 3
      test cases/common/153 recursive linking/meson.build
  8. 2
      test cases/common/153 recursive linking/shnodep/meson.build

@ -54,6 +54,9 @@ for _l in clike_langs:
clike_suffixes += lang_suffixes[_l]
clike_suffixes += ('h', 'll', 's')
# XXX: Use this in is_library()?
soregex = re.compile(r'.*\.so(\.[0-9]+)?(\.[0-9]+)?(\.[0-9]+)?$')
# All these are only for C-like languages; see `clike_langs` above.
def sort_clike(lang):
@ -495,20 +498,24 @@ class CompilerArgs(list):
def to_native(self):
# Check if we need to add --start/end-group for circular dependencies
# between static libraries.
# between static libraries, and for recursively searching for symbols
# needed by static libraries that are provided by object files or
# shared libraries.
if get_compiler_uses_gnuld(self.compiler):
group_started = False
global soregex
group_start = -1
for each in self:
if not each.startswith('-l') and not each.endswith('.a'):
if not each.startswith('-l') and not each.endswith('.a') and \
not soregex.match(each):
continue
i = self.index(each)
if not group_started:
if group_start < 0:
# First occurance of a library
self.insert(i, '-Wl,--start-group')
group_started = True
# Last occurance of a library
if group_started:
group_start = i
if group_start >= 0:
# Last occurance of a library
self.insert(i + 1, '-Wl,--end-group')
self.insert(group_start, '-Wl,--start-group')
return self.compiler.unix_args_to_native(self)
def append_direct(self, arg):

@ -0,0 +1,8 @@
#include "../lib.h"
int get_builto_value (void);
SYMBOL_EXPORT
int get_stodep_value (void) {
return get_builto_value ();
}

@ -0,0 +1,9 @@
# Test https://github.com/mesonbuild/meson/issues/2096
# Note that removing 'shnodep' from link_with: makes the error go away because
# then it is added after the static library is added to the link command.
test('shared-static', executable('shstexe', 'shstmain.c', link_with : [shnodep, stshdep]))
# Static library that needs a symbol defined in an object file. This already
# works, but good to add a test case early.
stodep = static_library('stodep', 'libsto.c')
test('stodep', executable('stodep', 'stomain.c', 'stobuilt.c', link_with : stodep))

@ -0,0 +1,16 @@
#include <stdio.h>
#include "../lib.h"
int get_stshdep_value (void);
int main(int argc, char *argv[]) {
int val;
val = get_stshdep_value ();
if (val != 1) {
printf("st1 value was %i instead of 1\n", val);
return -1;
}
return 0;
}

@ -0,0 +1,7 @@
#include "../lib.h"
SYMBOL_EXPORT
int get_builto_value (void) {
return 1;
}

@ -0,0 +1,16 @@
#include <stdio.h>
#include "../lib.h"
int get_stodep_value (void);
int main(int argc, char *argv[]) {
int val;
val = get_stodep_value ();
if (val != 1) {
printf("st1 value was %i instead of 1\n", val);
return -1;
}
return 0;
}

@ -24,3 +24,6 @@ subdir('3rdorderdeps')
# Circular dependencies between static libraries
# This requires the use of --start/end-group with GNU ld
subdir('circular')
# Various edge cases that have been reported
subdir('edge-cases')

@ -1 +1 @@
shnodep = shared_library('shnodep', 'lib.c')
shnodep = shared_library('shnodep', 'lib.c', version: '0.0.0')

Loading…
Cancel
Save