[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHirt9i-esjhZWF9yTsd+wBuMB+ebjVT33dY5VUkWHLcYREQpw@mail.gmail.com>
Date: Wed, 8 Nov 2023 17:39:45 +0800
From: WANG Rui <wangrui@...ngson.cn>
To: Xi Ruoyao <xry111@...111.site>
Cc: Huacai Chen <chenhuacai@...nel.org>,
WANG Xuerui <kernel@...0n.name>, linux-kernel@...r.kernel.org,
loongarch@...ts.linux.dev, linux-kbuild@...r.kernel.org,
llvm@...ts.linux.dev, loongson-kernel@...ts.loongnix.cn,
Fangrui Song <maskray@...gle.com>
Subject: Re: [PATCH] LoongArch: Disable module from accessing external data directly
On Wed, Nov 8, 2023 at 5:36 PM WANG Rui <wangrui@...ngson.cn> wrote:
>
> On Wed, Nov 8, 2023 at 5:26 PM Xi Ruoyao <xry111@...111.site> wrote:
> >
> > On Wed, 2023-11-08 at 17:20 +0800, WANG Rui wrote:
> > > > then the linked binary triggers a SIGBUS. Ideally this should be
> > > > detected by the linker at link time, but currently the BFD linker
> > > > fails
> > > > to detect this error (FWIW this flaw is caused by a really nasty
> > > > method
> > > > for the medium code model implementation). So to me -fno-direct-
> > > > access-
> > > > external-data is the default. I also grepped for -fdirect-access-
> > > > external-data in the kernel building system but I've not found any
> > > > match.
> > > >
> > > > Are you using a different version of Clang, or maybe Clang has some
> > > > configuration-time option to make -fdirect-access-external-data the
> > > > default?
> > >
> > > The clang enables `direct-access-external-data` by default in PIC and
> > > disables it by default in no-PIC. This also applies to PIE. [1]
> >
> > Oh sh*t:
> >
> > xry111@...men2 ~ $ clang t1.c -O2 -fno-pie -no-pie
> > xry111@...men2 ~ $ ./a.out
> > Bus error (core dumped)
> >
> > I'll consider it a Clang bug then.
>
> That's it, no copy relocations. As far as I know, copying relocations
> has some issues and is not recommended by Fangrui.
>
> For modules, if distance is not a problem, `no-pic` and
> `direct-access-external-data` can be together because the code is
> writable. Does it seem reasonable to exist?
Of course, for LoongArch, it is better for `no-pic` to disable
`direct-access-external-data` by default. I will send a patch.
--
WANG Rui
Powered by blists - more mailing lists