-
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.
rust: add start-group/end-group arguments for libraries
rustc tries to use lld to link Rust programs, via the -fuse-ld=lld flag to gcc or clang. However, when absent it will use the GNU linker. While lld seems to be adding --start-group/--end-group, ld.bfd can fail if these options are needed. This can cause difference between distros depending on how Rust is packaged (e.g. Ubuntu 22.04 and Debian bookworm seem to use ld.bfd). To improve compatibility, add --start-group and --end-group options like Meson already does with C programs. The code is slightly different due to the rustc-specific "--emit" and "--extern" options, therefore it's not really possible to share it with the C-like compiler mixin. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
- Loading branch information
Showing
8 changed files
with
90 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <stdio.h> | ||
#include "lib1.h" | ||
#include "lib2.h" | ||
|
||
void from_lib2(void) { | ||
printf("hello world"); | ||
} | ||
|
||
void c_func(void) { | ||
from_lib1(); | ||
} |
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,4 @@ | ||
#pragma once | ||
|
||
void from_lib2(void); | ||
void c_func(void); |
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 @@ | ||
#include <stdio.h> | ||
#include "lib1.h" | ||
#include "lib2.h" | ||
|
||
void from_lib1(void) | ||
{ | ||
from_lib2(); | ||
} |
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,3 @@ | ||
#pragma once | ||
|
||
void from_lib1(void); |
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 @@ | ||
#include "lib1.h" | ||
#include "lib2.h" | ||
|
||
void main() { | ||
c_func(); | ||
} |
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 @@ | ||
extern "C" { | ||
fn c_func(); | ||
} | ||
|
||
fn main() { | ||
unsafe { | ||
c_func(); | ||
} | ||
} |
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 @@ | ||
project('staticlib group', 'c', 'rust') | ||
|
||
ld_bfd = find_program('ld.bfd') | ||
if not ld_bfd.found() | ||
error('MESON_SKIP_TEST ld.bfd not found') | ||
endif | ||
|
||
lib1 = static_library('lib1', 'lib1.c') | ||
lib2 = static_library('lib2', 'lib2.c') | ||
executable('lib1first', 'main.rs', link_with : [lib1, lib2], | ||
rust_args: ['-C', 'lto=n', '-C', 'linker-plugin-lto=n', '-Clink-arg=-fuse-ld=bfd']) | ||
executable('lib2first', 'main.rs', link_with : [lib2, lib1], | ||
rust_args: ['-C', 'lto=n', '-C', 'linker-plugin-lto=n', '-Clink-arg=-fuse-ld=bfd']) |