From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by sourceware.org (Postfix) with ESMTPS id 59D20386D639 for ; Thu, 15 Feb 2024 22:09:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 59D20386D639 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 59D20386D639 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708034994; cv=none; b=XS3Tzx9mKN/SBpkhdqseQCMFsYNnZmlc8WcMRdhLojVO5rA4rpRcQAkYDshjz17n3Vi4S49rAGAw+E1o3hsgcoeUghCfDvMUxggtt4m4fPLb2dKR7iMUh/BOnGnWrkO0gHFOIkIQRc6Z3wTo2PmtkBnz0jpILvL0o0rtpXlSIfk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708034994; c=relaxed/simple; bh=xwJDd6bchBo5ll5EXmItGwBp8JJCOygvWr6segdeJbM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=q+fVv4v/DD1Bma6mUUC/NY+BYULqi4Ns6fVbVcpYy7JtrgxwuZxstbGkrwZvWJ0UTn40vENc5jugbVHwb4DyNSWul/MGff6edQAQLrhZI7Hcj3a6/JOPmy5KAcDrYEndns9P/Ce1DMu9VQTppz3yGWTshG1f8gOsa+UKgDDWXyA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1d7881b1843so12450565ad.3 for ; Thu, 15 Feb 2024 14:09:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708034990; x=1708639790; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=TXYgor2uUCj4oD/VoZlEmoPmxFU56okijtGe7SQ9E/I=; b=HK9l7EO6J4FajLUEJp0uhBegvnWoze3yxr3rfgMZ8vQZWm9zfBi0dCOc9YBlDBRAGE yHu8ou/sIiJ1Ab0BKSWEYXUTatVdOyu/QHL7O7+A9p4SPm0k3NxMOzd6l/BQ8+xEvF0Y EOFMt1WUy2zDAyUjCC0UE0YJ6EQCXU5vW9EaVZ2Y2CzVIGi3C5giYi8g235bXguV0zVS cDGBK4ebq/MJU6MD96dvb/kLaorMI6NFPhSVXdNoCPd8b0SeL6dxtCtEa7a1L7mmEsmI g+nU2IPlrTPHlJvQNi+yWkI0P8LQonwnR6OXRQt407gWg7rf3GW1Sixw55BjUhNbPYBf g1fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708034990; x=1708639790; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=TXYgor2uUCj4oD/VoZlEmoPmxFU56okijtGe7SQ9E/I=; b=Tjcz+TqzDQf/+AWjtKY/UxL7JIsxKm9f/83fxrTM4UUk34GVV1wdv25GH7IFFzK5Z5 vnkeQY2VVBJI49f0RuIn6kyQNjad42wumGXV1GTmWaVv7lwhtQQkQeZtzxt4qYHWai4d eSLvDpn5wBI4zrA7LZnnUwpOZRIwHLs1AI6PGxv0DH2py7TCN8Tpd0yrAyxDkcpXXFoV CdvtmdR8c3XPT8wuQvxZx9VvWXKyn2U7jFNkcW6SAWV9Bl7HMRAEDo/7EEqr/ejHd2MF HMWoGkavIiGgm3eFtUNdMK+XYR1bvgvauFwH6C+od7QA694GeguxICe5v7/CLEfr/Fgd 5qkQ== X-Gm-Message-State: AOJu0YwNtRJRQ0ycY/rM7tzxDrcVD//li3pLiP4FCfKWIonb3IgkBvg6 TRUBS+pTnTZwXIugscCRFkhQiXqdSSGGXl9A930k0TLogcYD77li X-Google-Smtp-Source: AGHT+IHUaWROVoOgrThBWRtXlrK6KNHJZ3S727Z2KR7nQlNafJRFA6LHYBWTcAyogYWSDfR+yd/xKg== X-Received: by 2002:a17:90b:386:b0:299:10d8:31cb with SMTP id ga6-20020a17090b038600b0029910d831cbmr2389012pjb.12.1708034990260; Thu, 15 Feb 2024 14:09:50 -0800 (PST) Received: from gnu-cfl-3.localdomain ([172.58.89.72]) by smtp.gmail.com with ESMTPSA id d30-20020a17090a6f2100b0029899165611sm4269829pjk.35.2024.02.15.14.09.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 14:09:49 -0800 (PST) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id C053174005D; Thu, 15 Feb 2024 14:09:48 -0800 (PST) From: "H.J. Lu" To: libc-alpha@sourceware.org Cc: goldstein.w.n@gmail.com, fweimer@redhat.com Subject: [PATCH v6 0/2] x86: Update _dl_tlsdesc_dynamic to preserve caller-saved registers Date: Thu, 15 Feb 2024 14:09:46 -0800 Message-ID: <20240215220948.1939297-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3011.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_ABUSEAT,RCVD_IN_DNSWL_NONE,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Changes in v5: 1. Drop Tile registers. Changes in v5: 1. Also preserve Tile registers. 2. Add an error check in i386 dl-tlsdesc-dynamic.h. Changes in v4: 1. Add APX registers to STATE_SAVE_MASK so that APX registers are saved in ld.so trampoline. 2. Also save x87 FPU stack registers for TLSDESC_CALL and TLS_DESC_CALL. 3. Change i386 _dl_tlsdesc_dynamic to IFUNC. 4. Rename GLRO(dl_x86_64_tlsdesc_dynamic) to GLRO(dl_x86_tlsdesc_dynamic) for both i386 and x86-64. 5. Update the testcase for i386 with a simple malloc interceptor. Changes in v3: 1. Don't add GLRO(dl_x86_64_tlsdesc_dynamic) to libc.a. Changes in v2: 1. Add GLRO(dl_x86_64_runtime_resolve) to optimize elf_machine_runtime_setup. --- Add APX registers to STATE_SAVE_MASK so that APX registers are saved in ld.so trampoline. This fixes BZ #31371. Compiler generates the following instruction sequence for GNU2 dynamic TLS access: leaq tls_var@TLSDESC(%rip), %rax call *tls_var@TLSCALL(%rax) or leal tls_var@TLSDESC(%ebx), %eax call *tls_var@TLSCALL(%eax) CALL instruction is transparent to compiler which assumes all registers, except for EFLAGS and RAX/EAX, are unchanged after CALL. When _dl_tlsdesc_dynamic is called, it calls __tls_get_addr on the slow path. __tls_get_addr is a normal function which doesn't preserve any caller-saved registers. _dl_tlsdesc_dynamic saved and restored integer caller-saved registers, but didn't preserve any other caller-saved registers. Add _dl_tlsdesc_dynamic IFUNC functions for FNSAVE, FXSAVE, XSAVE and XSAVEC to save and restore all caller-saved registers. This fixes BZ #31372. Add GLRO(dl_x86_64_runtime_resolve) with GLRO(dl_x86_tlsdesc_dynamic) to optimize elf_machine_runtime_setup. H.J. Lu (2): x86-64: Save APX registers in ld.so trampoline x86: Update _dl_tlsdesc_dynamic to preserve caller-saved registers elf/Makefile | 19 ++ elf/malloc-for-test.c | 32 ++++ elf/malloc-for-test.map | 6 + elf/tst-gnu2-tls2.c | 97 ++++++++++ elf/tst-gnu2-tls2.h | 26 +++ elf/tst-gnu2-tls2mod0.c | 28 +++ elf/tst-gnu2-tls2mod1.c | 28 +++ elf/tst-gnu2-tls2mod2.c | 28 +++ sysdeps/i386/dl-machine.h | 2 +- sysdeps/i386/dl-tlsdesc-dynamic.h | 190 +++++++++++++++++++ sysdeps/i386/dl-tlsdesc.S | 115 +++++------ sysdeps/i386/tst-gnu2-tls2.c | 5 + sysdeps/x86/Makefile | 7 +- sysdeps/x86/cpu-features.c | 56 +++++- sysdeps/x86/dl-procinfo.c | 16 ++ sysdeps/{x86_64 => x86}/features-offsets.sym | 2 + sysdeps/x86/malloc-for-test.c | 33 ++++ sysdeps/x86/sysdep.h | 56 +++++- sysdeps/x86_64/Makefile | 2 +- sysdeps/x86_64/dl-machine.h | 19 +- sysdeps/x86_64/dl-procinfo.c | 16 ++ sysdeps/x86_64/dl-tlsdesc-dynamic.h | 166 ++++++++++++++++ sysdeps/x86_64/dl-tlsdesc.S | 108 ++++------- sysdeps/x86_64/dl-trampoline-save.h | 34 ++++ sysdeps/x86_64/dl-trampoline-state.h | 51 +++++ sysdeps/x86_64/dl-trampoline.S | 20 +- sysdeps/x86_64/dl-trampoline.h | 34 +--- 27 files changed, 978 insertions(+), 218 deletions(-) create mode 100644 elf/malloc-for-test.c create mode 100644 elf/malloc-for-test.map create mode 100644 elf/tst-gnu2-tls2.c create mode 100644 elf/tst-gnu2-tls2.h create mode 100644 elf/tst-gnu2-tls2mod0.c create mode 100644 elf/tst-gnu2-tls2mod1.c create mode 100644 elf/tst-gnu2-tls2mod2.c create mode 100644 sysdeps/i386/dl-tlsdesc-dynamic.h create mode 100644 sysdeps/i386/tst-gnu2-tls2.c rename sysdeps/{x86_64 => x86}/features-offsets.sym (89%) create mode 100644 sysdeps/x86/malloc-for-test.c create mode 100644 sysdeps/x86_64/dl-tlsdesc-dynamic.h create mode 100644 sysdeps/x86_64/dl-trampoline-save.h create mode 100644 sysdeps/x86_64/dl-trampoline-state.h -- 2.43.0