-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
compilers: Try harder to dedup builtin libs
Compiler internal libs should always be de-duplicated, no matter what. Closes #2150
- Loading branch information
Showing
12 changed files
with
103 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,9 @@ | |
'vala': 'VALAFLAGS', | ||
'rust': 'RUSTFLAGS'} | ||
|
||
# execinfo is a compiler lib on BSD | ||
unixy_compiler_internal_libs = ('m', 'c', 'pthread', 'dl', 'rt', 'execinfo') | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
nirbheek
Author
Member
|
||
|
||
# All these are only for C-linkable languages; see `clink_langs` above. | ||
|
||
def sort_clink(lang): | ||
|
@@ -659,6 +662,9 @@ class CompilerArgs(list): | |
# Only UNIX shared libraries require this. Others have a fixed extension. | ||
dedup1_regex = re.compile(r'([\/\\]|\A)lib.*\.so(\.[0-9]+)?(\.[0-9]+)?(\.[0-9]+)?$') | ||
dedup1_args = ('-c', '-S', '-E', '-pipe', '-pthread') | ||
# In generate_link() we add external libs without de-dup, but we must | ||
# *always* de-dup these because they're special arguments to the linker | ||
always_dedup_args = tuple('-l' + lib for lib in unixy_compiler_internal_libs) | ||
compiler = None | ||
|
||
def _check_args(self, args): | ||
|
@@ -793,7 +799,7 @@ def extend_preserving_lflags(self, iterable): | |
normal_flags = [] | ||
lflags = [] | ||
for i in iterable: | ||
if i.startswith('-l') or i.startswith('-L'): | ||
if i not in self.always_dedup_args and (i.startswith('-l') or i.startswith('-L')): | ||
lflags.append(i) | ||
else: | ||
normal_flags.append(i) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <stdio.h> | ||
#include <liba.h> | ||
#include <libb.h> | ||
|
||
int | ||
main(void) | ||
{ | ||
printf("start value = %d\n", liba_get()); | ||
liba_add(2); | ||
libb_mul(5); | ||
printf("end value = %d\n", liba_get()); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
executable('app', 'app.c', | ||
dependencies: [get_variable('dep_liba'), get_variable('dep_libb')]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include "liba.h" | ||
|
||
static int val; | ||
|
||
void liba_add(int x) | ||
{ | ||
val += x; | ||
} | ||
|
||
void liba_sub(int x) | ||
{ | ||
val -= x; | ||
} | ||
|
||
int liba_get(void) | ||
{ | ||
return val; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef LIBA_H_ | ||
#define LIBA_H_ | ||
|
||
void liba_add(int x); | ||
void liba_sub(int x); | ||
int liba_get(void); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
deps = [dependency('threads'), cc.find_library('dl'), cc.find_library('m')] | ||
|
||
liba = library('a', 'liba.c', | ||
dependencies: deps) | ||
|
||
liba_dep = declare_dependency(link_with: liba, | ||
include_directories: include_directories('.'), | ||
dependencies: deps) | ||
|
||
set_variable('dep_liba', liba_dep) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include <liba.h> | ||
#include "libb.h" | ||
|
||
void libb_mul(int x) | ||
{ | ||
liba_add(liba_get() * (x - 1)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#ifndef _LIBB_H_ | ||
#define _LIBB_H_ | ||
|
||
void libb_mul(int x); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
libb = library('b', 'libb.c', | ||
dependencies: liba_dep) | ||
|
||
libb_dep = declare_dependency(link_with: libb, | ||
include_directories: include_directories('.'), | ||
dependencies: liba_dep) | ||
|
||
set_variable('dep_libb', libb_dep) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
project('temp', 'C') | ||
|
||
cc = meson.get_compiler('c') | ||
|
||
subdir('liba') | ||
subdir('libb') | ||
subdir('app') |
Note that
execinfo
is not an internal library with e.g. Clang on OpenBSD. This breaks detection oflibexecinfo
on OpenBSD.