Message ID | 20240213041501.2494232-1-hjl.tools@gmail.com |
---|---|
Headers |
Return-Path: <libc-alpha-bounces+patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A2A923858428 for <patchwork@sourceware.org>; Tue, 13 Feb 2024 04:15:35 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by sourceware.org (Postfix) with ESMTPS id A22C53858D20 for <libc-alpha@sourceware.org>; Tue, 13 Feb 2024 04:15:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A22C53858D20 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 A22C53858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707797706; cv=none; b=eo6tw77QKvtBb9lTd+Gdm6PVOa+EzS0nAof+3giSKlQ6s/XXA00wIzilktLZ6Q+ctkjKGXcVWkIk/xhmiaKUoFIuhAINULpAUiXYeSIU3naEzQvB9VkBy8KoxB9vYdC8WkKg58QODnqjvl3ziTlJNYQeiqhO9WvIOIo42S+ZiQY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707797706; c=relaxed/simple; bh=KUxG9gmc2yEJ4a2IyCiyPLlXwVVNgHuxbqBwQ66NvKM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=qtkJKzepZLpyk6Otq9H9/AwM8OT58m3eiVcXYo6vu36RHOimlxh7EE3Fa+tGKZRLCR9TGAvzCuACZdL4Fyw+Bx7hdNfoPnygC9XPIVGOY1jH3fmWVeDZ49xzKCUc/r5MPPyABu4gCck4hnNHiBNdizpaOWGsdfJkbnXe+7Xw3FE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1d74045c463so30809895ad.3 for <libc-alpha@sourceware.org>; Mon, 12 Feb 2024 20:15:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707797703; x=1708402503; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=zo5SK4raoiPUR/aW7aBDhAONn6cYcvXElbUzBDDaSTY=; b=LTLbc40U4F1LREy8ZMXBIqczQD3s0PXJejnzB9oZbaOqKJZWdg70r9atPG/bK4by1J nz9WHfHiA7AZK85RRkJu3m5LZUxWIZAhPbZh+irbr72K+nivE4smXm77m3XmhLTSY1T6 +jE2Ijd9q0IYQU+SDQQxarFVfL/CAoUW8ath8JSsxe1HzPPbZ84tpjFoGeoLmK4saweD fg7t3eXxrIhYpysHWc1u4CaNVoHoqCVqWazWjCCKc0smze/yqG5boHIojHIDxVlzBf9W M8eGzMlwXzEb5mPzECaefx8L/5mX11tTJvdUN0gFJXR6GXrsKYOvbv9Zb2m6u4ryfO7S 0Yng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707797703; x=1708402503; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zo5SK4raoiPUR/aW7aBDhAONn6cYcvXElbUzBDDaSTY=; b=q01a42eoDeUdKNa3UdQRMHFjmEYq9aVh22jRi7hztUoByXkzSc4n3Blhra3fr2QD2t eAT1XGGocJnd3haGq5GUkUFzhXHL9KbuiJIqsaHPEYYozAAa6c5zbbMDTdGbMrOqPWKj 7DXt73MlQfxud52ijiLXxNL+ehutxN4lUQMG3Lb5H1wWGj00AnR39X1tAFbTzSzhM/KV 7WdcDyquPGh5yF9EiF8cVxUFo+/OhrEUxpR17RtAX3WrfHwwj7DQpTPGAKL7YfAFtCQt XPhcZzY4Amf37gJn2YrE/I7K4QNut12teKhwijAI8mN70kPjCK7HUvEWWUqJ/vnkbkHu NfqA== X-Gm-Message-State: AOJu0Yw+z0Ny8pDJTMjX4qj9FTtCu0VlycXEW9ci+naqb9HNR2xS7wQ1 owPSSaK3DYXrGve4sjLdSYtUcd707TBUBO1X0ODYk5FTomOxDf9SnBlpd73U X-Google-Smtp-Source: AGHT+IHITgRyEJdyNzOvMVjT6mmOLJuUqI/BaDbDia1MgJd8npfyW25w1hX2z/fwi/XRC16Mpt7cFQ== X-Received: by 2002:a17:902:eccd:b0:1d9:5ef2:abdd with SMTP id a13-20020a170902eccd00b001d95ef2abddmr9604243plh.0.1707797703329; Mon, 12 Feb 2024 20:15:03 -0800 (PST) Received: from gnu-cfl-3.localdomain ([172.56.168.224]) by smtp.gmail.com with ESMTPSA id k3-20020a170902e90300b001db3361bc1dsm359019pld.102.2024.02.12.20.15.02 for <libc-alpha@sourceware.org> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 20:15:02 -0800 (PST) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id 6E90B74005D for <libc-alpha@sourceware.org>; Mon, 12 Feb 2024 20:15:01 -0800 (PST) From: "H.J. Lu" <hjl.tools@gmail.com> To: libc-alpha@sourceware.org Subject: [PATCH v4 0/2] x86: Update _dl_tlsdesc_dynamic to preserve caller-saved registers Date: Mon, 12 Feb 2024 20:14:59 -0800 Message-ID: <20240213041501.2494232-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=-3012.4 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 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list <libc-alpha.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/libc-alpha/> List-Post: <mailto:libc-alpha@sourceware.org> List-Help: <mailto:libc-alpha-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=subscribe> Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org |
Series |
x86: Update _dl_tlsdesc_dynamic to preserve caller-saved registers
|
|
Message
H.J. Lu
Feb. 13, 2024, 4:14 a.m. UTC
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 | 187 +++++++++++++++++++ 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 | 54 +++++- 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, 973 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