lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <CAFRnB2UO+H3kbkn9L61Mu-g2Z4K=rLJ3STwEKPNUG1R0VWzTmQ@mail.gmail.com>
Date:   Sun, 4 Dec 2022 17:49:59 -0500
From:   Alex Gaynor <alex.gaynor@...il.com>
To:     Gary Guo <gary@...yguo.net>
Cc:     Miguel Ojeda <ojeda@...nel.org>,
        Wedson Almeida Filho <wedsonaf@...il.com>,
        Boqun Feng <boqun.feng@...il.com>,
        Björn Roy Baron <bjorn3_gh@...tonmail.com>,
        rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] rust: make compiler-builtin stubs non-global

Can you add a comment to compiler_builtins.rs reminding people that if
they add an additional intrinsic, they may also need to add it to
redirect-intrinsics in the Makefile?

Alex

On Sun, Dec 4, 2022 at 5:44 PM Gary Guo <gary@...yguo.net> wrote:
>
> Currently we define a number of stubs for compiler-builtin intrinsics
> that compiled libcore generates. The defined stubs are weak so they will
> not conflict with genuine implementation of these intrinsics, but their
> effect is global and will cause non-libcore code that accidently
> generate these intrinsics calls compile and bug on runtime.
>
> Instead of defining a stub that can affect all code, this patch uses
> objcopy's `--redefine-sym` flag to redirect these calls (from libcore
> only) to a prefixed version (e.g. redirect `__multi3` to `__rust_multi3`),
> so we can define panciking stubs that are only visible to libcore.
>
> Signed-off-by: Gary Guo <gary@...yguo.net>
> ---
> This patch was previous discussed on GitHub.
>
> Link: https://github.com/Rust-for-Linux/linux/pull/779
>
> To: Miguel Ojeda <ojeda@...nel.org>
> To: Alex Gaynor <alex.gaynor@...il.com>
> To: Wedson Almeida Filho <wedsonaf@...il.com>
> To: Boqun Feng <boqun.feng@...il.com>
> To: Björn Roy Baron <bjorn3_gh@...tonmail.com>
> Cc: rust-for-linux@...r.kernel.org
> Cc: linux-kernel@...r.kernel.org
> ---
>  rust/Makefile             | 14 ++++++++++++++
>  rust/compiler_builtins.rs |  2 +-
>  2 files changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/rust/Makefile b/rust/Makefile
> index ff70c4c916f8..aed6f7eca36f 100644
> --- a/rust/Makefile
> +++ b/rust/Makefile
> @@ -359,8 +359,22 @@ rust-analyzer:
>         $(Q)$(srctree)/scripts/generate_rust_analyzer.py $(srctree) $(objtree) \
>                 $(RUST_LIB_SRC) > $(objtree)/rust-project.json
>
> +redirect-intrinsics = \
> +       __eqsf2 __gesf2 __lesf2 __nesf2 __unordsf2 \
> +       __unorddf2 \
> +       __muloti4 __multi3 \
> +       __udivmodti4 __udivti3 __umodti3
> +
> +ifneq ($(or $(CONFIG_ARM64),$(and $(CONFIG_RISCV),$(CONFIG_64BIT))),)
> +       # These intrinsics are defined for ARM64 and RISCV64
> +       redirect-intrinsics += \
> +               __ashrti3 \
> +               __ashlti3 __lshrti3
> +endif
> +
>  $(obj)/core.o: private skip_clippy = 1
>  $(obj)/core.o: private skip_flags = -Dunreachable_pub
> +$(obj)/core.o: private rustc_objcopy = $(foreach sym,$(redirect-intrinsics),--redefine-sym $(sym)=__rust$(sym))
>  $(obj)/core.o: private rustc_target_flags = $(core-cfgs)
>  $(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs $(obj)/target.json FORCE
>         $(call if_changed_dep,rustc_library)
> diff --git a/rust/compiler_builtins.rs b/rust/compiler_builtins.rs
> index f8f39a3e6855..1f05f93f2187 100644
> --- a/rust/compiler_builtins.rs
> +++ b/rust/compiler_builtins.rs
> @@ -28,7 +28,7 @@ macro_rules! define_panicking_intrinsics(
>      ($reason: tt, { $($ident: ident, )* }) => {
>          $(
>              #[doc(hidden)]
> -            #[no_mangle]
> +            #[export_name = concat!("__rust", stringify!($ident))]
>              pub extern "C" fn $ident() {
>                  panic!($reason);
>              }
>
> ---
> base-commit: b9ecf9b9ac5969d7b7ea786ce5c76e24246df2c5
> change-id: 20221204-compiler-builtin-bb03aa6c4400
>
> Best regards,
> --
> Gary Guo <gary@...yguo.net>



-- 
All that is necessary for evil to succeed is for good people to do nothing.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ