From nobody Fri Aug 27 14:24:58 2021 X-Original-To: freebsd-current@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 1519E178DACD for ; Fri, 27 Aug 2021 14:25:12 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4Gx26v5bNbz4mMM; Fri, 27 Aug 2021 14:25:11 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.16.1/8.16.1) with ESMTPS id 17REOwIL055119 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Fri, 27 Aug 2021 17:25:01 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 17REOwIL055119 Received: (from kostik@localhost) by tom.home (8.16.1/8.16.1/Submit) id 17REOwlN055118; Fri, 27 Aug 2021 17:24:58 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Fri, 27 Aug 2021 17:24:58 +0300 From: Konstantin Belousov To: =?utf-8?Q?T=C4=B3l?= Coosemans Cc: Dimitry Andric , freebsd-current@freebsd.org Subject: Re: i386 kernel modules unusable due to .plt sections Message-ID: References: <20210827154130.7a5b141c@FreeBSD.org> List-Id: Discussions about the use of FreeBSD-current List-Archive: https://lists.freebsd.org/archives/freebsd-current List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-current@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20210827154130.7a5b141c@FreeBSD.org> X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.5 X-Spam-Checker-Version: SpamAssassin 3.4.5 (2021-03-20) on tom.home X-Rspamd-Queue-Id: 4Gx26v5bNbz4mMM X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[] X-ThisMailContainsUnwantedMimeParts: N On Fri, Aug 27, 2021 at 03:41:30PM +0200, Tijl Coosemans wrote: > Hi, > > I use devel/llvm* to build base and just switched to llvm12. It seems > that on i386 clang12 uses R_386_PLT32 relocations for some calls to at > least memset, memcpy and __stack_chk_fail (clang11 uses R_386_PC32). > These are converted to R_386_JMP_SLOT relocations by the linker which > aren't supported by the kernel, e.g. loading linux.ko gives "kldload: > unexpected relocation type" from sys/i386/i386/elf_machdep.c. The PLT > entries also depend on a base pointer in %ebx but kernel modules aren't > compiled with -fPIC, so this can't work and I suspect this is a > regression in clang12. > > The following code shows the difference between clang11 and clang12: > > -------- > #include > > void * > test_memset(void *p, int c, size_t len) { > return (memset(p, c, len)); > } > > void * > test_memcpy(void *dst, const void *src, size_t len) { > return (memcpy(dst, src, len)); > } > > void * > test_memmove(void *dst, const void *src, size_t len) { > return (memmove(dst, src, len)); > } > -------- > > Output of "readelf -r test.o" when compiled with "clang12 -c test.c -m32": > r_offset r_info r_type st_value st_name > 0000002c 00000504 R_386_PLT32 00000000 memset > 00000067 00000304 R_386_PLT32 00000000 memcpy > 000000a7 00000402 R_386_PC32 00000000 memmove > > With clang11: > r_offset r_info r_type st_value st_name > 00000036 00000502 R_386_PC32 00000000 memset > 00000083 00000302 R_386_PC32 00000000 memcpy > 000000d2 00000402 R_386_PC32 00000000 memmove Are you asking (for somebody) to add R_386_JMP_SLOT to i386/elf_machdep.c? Like this, not even built. diff --git a/sys/i386/i386/elf_machdep.c b/sys/i386/i386/elf_machdep.c index 3754b36d9e33..a26a4189e0ee 100644 --- a/sys/i386/i386/elf_machdep.c +++ b/sys/i386/i386/elf_machdep.c @@ -245,6 +245,7 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbase, const void *data, break; case R_386_GLOB_DAT: /* S */ + case R_386_JMP_SLOT: error = lookup(lf, symidx, 1, &addr); if (error != 0) return (-1);