PATH:
usr
/
src
/
kernels
/
5.14.0-611.49.1.el9_7.x86_64
/
scripts
// SPDX-License-Identifier: GPL-2.0 //! The custom target specification file generator for `rustc`. //! //! To configure a target from scratch, a JSON-encoded file has to be passed //! to `rustc` (introduced in [RFC 131]). These options and the file itself are //! unstable. Eventually, `rustc` should provide a way to do this in a stable //! manner. For instance, via command-line arguments. Therefore, this file //! should avoid using keys which can be set via `-C` or `-Z` options. //! //! [RFC 131]: https://rust-lang.github.io/rfcs/0131-target-specification.html use std::{ collections::HashMap, fmt::{Display, Formatter, Result}, io::BufRead, }; enum Value { Boolean(bool), Number(i32), String(String), Object(Object), } type Object = Vec<(String, Value)>; /// Minimal "almost JSON" generator (e.g. no `null`s, no arrays, no escaping), /// enough for this purpose. impl Display for Value { fn fmt(&self, formatter: &mut Formatter<'_>) -> Result { match self { Value::Boolean(boolean) => write!(formatter, "{}", boolean), Value::Number(number) => write!(formatter, "{}", number), Value::String(string) => write!(formatter, "\"{}\"", string), Value::Object(object) => { formatter.write_str("{")?; if let [ref rest @ .., ref last] = object[..] { for (key, value) in rest { write!(formatter, "\"{}\": {},", key, value)?; } write!(formatter, "\"{}\": {}", last.0, last.1)?; } formatter.write_str("}") } } } } struct TargetSpec(Object); impl TargetSpec { fn new() -> TargetSpec { TargetSpec(Vec::new()) } } trait Push<T> { fn push(&mut self, key: &str, value: T); } impl Push<bool> for TargetSpec { fn push(&mut self, key: &str, value: bool) { self.0.push((key.to_string(), Value::Boolean(value))); } } impl Push<i32> for TargetSpec { fn push(&mut self, key: &str, value: i32) { self.0.push((key.to_string(), Value::Number(value))); } } impl Push<String> for TargetSpec { fn push(&mut self, key: &str, value: String) { self.0.push((key.to_string(), Value::String(value))); } } impl Push<&str> for TargetSpec { fn push(&mut self, key: &str, value: &str) { self.push(key, value.to_string()); } } impl Push<Object> for TargetSpec { fn push(&mut self, key: &str, value: Object) { self.0.push((key.to_string(), Value::Object(value))); } } impl Display for TargetSpec { fn fmt(&self, formatter: &mut Formatter<'_>) -> Result { // We add some newlines for clarity. formatter.write_str("{\n")?; if let [ref rest @ .., ref last] = self.0[..] { for (key, value) in rest { write!(formatter, " \"{}\": {},\n", key, value)?; } write!(formatter, " \"{}\": {}\n", last.0, last.1)?; } formatter.write_str("}") } } struct KernelConfig(HashMap<String, String>); impl KernelConfig { /// Parses `include/config/auto.conf` from `stdin`. fn from_stdin() -> KernelConfig { let mut result = HashMap::new(); let stdin = std::io::stdin(); let mut handle = stdin.lock(); let mut line = String::new(); loop { line.clear(); if handle.read_line(&mut line).unwrap() == 0 { break; } if line.starts_with('#') { continue; } let (key, value) = line.split_once('=').expect("Missing `=` in line."); result.insert(key.to_string(), value.trim_end_matches('\n').to_string()); } KernelConfig(result) } /// Does the option exist in the configuration (any value)? /// /// The argument must be passed without the `CONFIG_` prefix. /// This avoids repetition and it also avoids `fixdep` making us /// depend on it. fn has(&self, option: &str) -> bool { let option = "CONFIG_".to_owned() + option; self.0.contains_key(&option) } } fn main() { let cfg = KernelConfig::from_stdin(); let mut ts = TargetSpec::new(); // `llvm-target`s are taken from `scripts/Makefile.clang`. if cfg.has("X86_64") { ts.push("arch", "x86_64"); ts.push( "data-layout", "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128", ); let mut features = "-3dnow,-3dnowa,-mmx,+soft-float".to_string(); if cfg.has("MITIGATION_RETPOLINE") { features += ",+retpoline-external-thunk"; } ts.push("features", features); ts.push("llvm-target", "x86_64-linux-gnu"); ts.push("target-pointer-width", "64"); } else { panic!("Unsupported architecture"); } ts.push("emit-debug-gdb-scripts", false); ts.push("frame-pointer", "may-omit"); ts.push( "stack-probes", vec![("kind".to_string(), Value::String("none".to_string()))], ); // Everything else is LE, whether `CPU_LITTLE_ENDIAN` is declared or not // (e.g. x86). It is also `rustc`'s default. if cfg.has("CPU_BIG_ENDIAN") { ts.push("target-endian", "big"); } println!("{}", ts); }
[+]
..
[-] headers_check.pl
[edit]
[+]
genksyms
[-] cleanfile
[edit]
[+]
dtc
[-] file-size.sh
[edit]
[-] cleanpatch
[edit]
[-] checkdeclares.pl
[edit]
[-] extract-cert
[edit]
[-] module.lds
[edit]
[-] decode_stacktrace.sh
[edit]
[-] profile2linkerlist.pl
[edit]
[-] extract-sys-certs.pl
[edit]
[-] Makefile.randstruct
[edit]
[-] jobserver-exec
[edit]
[-] Kbuild.include
[edit]
[-] unifdef
[edit]
[-] modules-check.sh
[edit]
[-] check_extable.sh
[edit]
[-] mkuboot.sh
[edit]
[-] Makefile.userprogs
[edit]
[+]
gcc-plugins
[-] decodecode
[edit]
[-] tools-support-relr.sh
[edit]
[-] Makefile.kcov
[edit]
[-] cc-can-link.sh
[edit]
[-] kallsyms
[edit]
[-] Lindent
[edit]
[-] recordmcount.pl
[edit]
[-] Makefile.gcc-plugins
[edit]
[-] remove-stale-files
[edit]
[-] stackusage
[edit]
[-] kernel-doc
[edit]
[-] gen_ksymdeps.sh
[edit]
[-] install.sh
[edit]
[-] get_maintainer.pl
[edit]
[-] Makefile.compiler
[edit]
[-] sorttable.c
[edit]
[-] xen-hypercalls.sh
[edit]
[-] extract-module-sig.pl
[edit]
[-] spdxcheck-test.sh
[edit]
[-] faddr2line
[edit]
[-] Makefile.package
[edit]
[-] kallsyms.c
[edit]
[-] gcc-x86_32-has-stack-protector.sh
[edit]
[-] get_abi.pl
[edit]
[-] mkcompile_h
[edit]
[-] checkpatch.pl
[edit]
[-] sign-file
[edit]
[-] Makefile
[edit]
[-] gcc-x86_64-has-stack-protector.sh
[edit]
[-] Makefile.build
[edit]
[-] leaking_addresses.pl
[edit]
[-] syscallnr.sh
[edit]
[-] markup_oops.pl
[edit]
[-] checkversion.pl
[edit]
[-] headerdep.pl
[edit]
[-] Makefile.kmsan
[edit]
[-] recordmcount.h
[edit]
[-] depmod.sh
[edit]
[-] subarch.include
[edit]
[-] Makefile.kcsan
[edit]
[-] prune-kernel
[edit]
[-] sphinx-pre-install
[edit]
[-] Makefile.extrawarn
[edit]
[-] ld-version.sh
[edit]
[+]
gdb
[+]
atomic
[-] ver_linux
[edit]
[-] Makefile.host
[edit]
[-] parse-maintainers.pl
[edit]
[-] as-version.sh
[edit]
[-] objdiff
[edit]
[-] stackdelta
[edit]
[-] tags.sh
[edit]
[-] sign-file.c
[edit]
[-] objdump-func
[edit]
[-] insert-sys-cert.c
[edit]
[-] gen_packed_field_checks.c
[edit]
[-] Makefile.modinst
[edit]
[-] coccicheck
[edit]
[-] syscalltbl.sh
[edit]
[-] documentation-file-ref-check
[edit]
[-] Makefile.asm-generic
[edit]
[-] adjust_autoksyms.sh
[edit]
[-] bin2c.c
[edit]
[-] patch-kernel
[edit]
[-] generate_rust_target.rs
[edit]
[-] config
[edit]
[-] Makefile.lib
[edit]
[-] test_fortify.sh
[edit]
[+]
mod
[-] gfp-translate
[edit]
[-] headers_install.sh
[edit]
[-] pahole-version.sh
[edit]
[-] mksysmap
[edit]
[-] find-unused-docs.sh
[edit]
[-] extract_xc3028.pl
[edit]
[-] dev-needs.sh
[edit]
[-] makelst
[edit]
[-] bloat-o-meter
[edit]
[-] gen_autoksyms.sh
[edit]
[+]
basic
[-] setlocalversion
[edit]
[-] Makefile.modpost
[edit]
[-] link-vmlinux.sh
[edit]
[-] nsdeps
[edit]
[-] gcc-ld
[edit]
[-] Makefile.vmlinux_o
[edit]
[-] recordmcount.c
[edit]
[-] min-tool-version.sh
[edit]
[-] const_structs.checkpatch
[edit]
[-] cc-version.sh
[edit]
[-] checkincludes.pl
[edit]
[-] extract-cert.c
[edit]
[+]
selinux
[+]
coccinelle
[-] get_dvb_firmware
[edit]
[+]
clang-tools
[+]
package
[-] extract-ikconfig
[edit]
[-] check-sysctl-docs
[edit]
[-] checkkconfigsymbols.py
[edit]
[-] Makefile.clean
[edit]
[-] checksyscalls.sh
[edit]
[-] split-man.pl
[edit]
[+]
ksymoops
[-] show_delta
[edit]
[-] Makefile.modfinal
[edit]
[-] sorttable
[edit]
[-] spelling.txt
[edit]
[-] extract-vmlinux
[edit]
[-] export_report.pl
[edit]
[-] Makefile.btf
[edit]
[-] asn1_compiler.c
[edit]
[-] unifdef.c
[edit]
[-] sorttable.h
[edit]
[-] get_feat.pl
[edit]
[+]
include
[+]
kconfig
[-] bpf_doc.py
[edit]
[-] syscallhdr.sh
[edit]
[-] Makefile.dtbinst
[edit]
[-] diffconfig
[edit]
[-] xz_wrap.sh
[edit]
[-] Makefile.vmlinux
[edit]
[-] checkstack.pl
[edit]
[-] bootgraph.pl
[edit]
[-] Makefile.kasan
[edit]
[-] Makefile.headersinst
[edit]
[-] generate_initcall_order.pl
[edit]
[-] asn1_compiler
[edit]
[-] Kconfig.include
[edit]
[+]
dummy-tools
[-] module.lds.S
[edit]
[-] Makefile.ubsan
[edit]