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

Add support for FreeBSD on PowerPC64 #57758

Closed
wants to merge 9 commits into from
Closed
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
1 change: 1 addition & 0 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ def default_build_triple():
if cputype == 'powerpc' and ostype == 'unknown-freebsd':
cputype = subprocess.check_output(
['uname', '-p']).strip().decode(default_encoding)

cputype_mapper = {
'BePC': 'i686',
'aarch64': 'aarch64',
Expand Down
7 changes: 6 additions & 1 deletion src/librustc_llvm/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,12 @@ fn main() {
} else if cxxflags.contains("stdlib=libc++") {
println!("cargo:rustc-link-lib=c++");
} else {
println!("cargo:rustc-link-lib={}", stdcppname);
if target.contains("powerpc64-unknown-freebsd") {
println!("cargo:rustc-link-search=native=/usr/local/lib/gcc6");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does llvm-config not print this path out? If I remember my freebsd correctly, this would mean that gcc would be required to build rustc then. Which is not that big of a deal, but still something to improve on.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FreeBSD on powerpc64 ships an old version of gcc (4.2.1) in the 'base' system, since it can't build llvm I had to use gcc7 from our 'ports tree'. For whatever reason the linker tried to link 'something' against libstdc++ from gcc-4.2.1 instead of libstdc++ from gcc7 and the link failed (I was not able to figure out how to pass -Wl,-rpath=/usr/local/lib/gcc7). Linking to a static version of libstdc++ made the problem go away.
This is just an ugly hack to fix a FreeBSD problem and should probably stays as a patch file in our 'ports tree'

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put gcc8, this is our default gcc version since a few weeks.

println!("cargo:rustc-link-lib=static=stdc++");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This particular piece of code should perhaps be moved slightly up to where stdcppname variable is assigned.

} else {
println!("cargo:rustc-link-lib={}", stdcppname);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/librustc_target/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ supported_targets! {

("aarch64-unknown-freebsd", aarch64_unknown_freebsd),
("i686-unknown-freebsd", i686_unknown_freebsd),
("powerpc64-unknown-freebsd", powerpc64_unknown_freebsd),
("x86_64-unknown-freebsd", x86_64_unknown_freebsd),

("i686-unknown-dragonfly", i686_unknown_dragonfly),
Expand Down
22 changes: 22 additions & 0 deletions src/librustc_target/spec/powerpc64_unknown_freebsd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use spec::{LinkerFlavor, Target, TargetResult};

pub fn target() -> TargetResult {
let mut base = super::freebsd_base::opts();
base.cpu = "ppc64".to_string();
base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-m64".to_string());
base.max_atomic_width = Some(64);

Ok(Target {
llvm_target: "powerpc64-unknown-freebsd".to_string(),
target_endian: "big".to_string(),
target_pointer_width: "64".to_string(),
target_c_int_width: "32".to_string(),
data_layout: "E-m:e-i64:64-n32:64".to_string(),
arch: "powerpc64".to_string(),
target_os: "freebsd".to_string(),
target_env: String::new(),
target_vendor: "unknown".to_string(),
linker_flavor: LinkerFlavor::Gcc,
options: base,
})
}