From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yw1-x1136.google.com (mail-yw1-x1136.google.com [IPv6:2607:f8b0:4864:20::1136]) by sourceware.org (Postfix) with ESMTPS id 35BAE385829E for ; Fri, 16 Feb 2024 12:59:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 35BAE385829E 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 35BAE385829E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1136 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708088372; cv=none; b=HQIcUHL+K6h77AufrKSfgJzLbgDOnS5zPk/KNp3cdl70Z+cZHORglrbPMHlVMkRiDbViqK8myHMBiVJgTDeHw69o2pGN1cX8J9NGoRiL/m41BC1zOLjXDwuUmeKiZrbIfNB/e336t/ck0bb/tWDRWgcSqc9fGpjGV0eQIxFRRtI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708088372; c=relaxed/simple; bh=zBI9oNrBmSmAZgjMSeSwZg4Xe3PG2AY6L5ijolfpt3U=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=NXmVYU2C9HnFKmROTy5afGwv7B7K92nTqiY/m3svOJAZisl+1a4xH5wffThXMBJ4j+wJDSYD8jfNlkSBqrXw7R/K1aWwrXMI+uCa+1DMZU9tYgq52GFg7JtqigphZIKwHz1FcURgW9VhHnAKAJNUOceiisz/F+Z5lS7acsOV2Fo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yw1-x1136.google.com with SMTP id 00721157ae682-60806c3523aso988867b3.1 for ; Fri, 16 Feb 2024 04:59:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708088369; x=1708693169; darn=sourceware.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=KPyowT0b6tG+FywtC0hwn6mNkXaIs6D6bsMIcXAOZaQ=; b=ZyUDB5duxrb367cjHjvW6EptIy1mmSY6xiaXiPpisD1p4oTy75oP04XG4KA7wsq6wU cMQg2qcGEkDQmZKhp7gPGoUKJhdTeH1jpe5eKvQ+l7HnMWck3T+dr/UqYQj6uNnQPe58 92/1JjN2bP+7pdS/wVTi1fYcpBQ9ldTliXbpqrfdHsT9aR052Slxct0CH9SPSckas/J8 DAW5iC7xFRkkd+5B/bASZ86hH0ggMFvazo2wxtKJleFF5Nb+XY2jm+NPmc14448EPjHX Q8dQchv0/0luhHMnl91qZqtPpx2+Qvsx9Rb7ViQG/ei7+BAB7h/qT/4pxY58p8DJVw2y lB0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708088369; x=1708693169; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KPyowT0b6tG+FywtC0hwn6mNkXaIs6D6bsMIcXAOZaQ=; b=IT9qvfA85GejIqaFlmZNoOcyEU2IRG200QuH+Fe8xzoFYThPQYM+DSZTXNieXKfnTM ZVMGPUiyUjOb5HRx1+tcIFrTRp0lO5ld2PK10xR3bKSCYQyXuEZD3JKgBgPTIudcpcdg BK48KLw8bHlIAnFsvbMf0Bpbj/CenTIFwA4ORIstmm6NX5gNpsXyGKSngVOgn2LIZ9vY iWSJCPKdmJsv2YVphrgRxNfOD4+IxGbh3uCudxbnVdCbgavPrnD2vrJ+zXuj/LdmiFZO IN98+9aN0I5X3YkV7U3F9tIXxBQbjcbU5UL0yDHQ5p3+RQIUoSGO/tlsrK5WJetEA6cj jdCQ== X-Forwarded-Encrypted: i=1; AJvYcCXthezHEjN45gY0Qv0/LoQAJHdfBkkJEvDuqGf1JfZyK4B+wtnlMFcr9XSKwVpef88HZclQ8rtpLfbMTc+NgQTKevt3iJx7geDV X-Gm-Message-State: AOJu0YwJ7QgQh3V9xAYJ6IfRuop1YlaFswmIpWjEcA5NoJir9GGxxw1n t1WwzTJuHLVlWHq1uvHPR7jjTz5LGHbBu4F/3pEkz7gZHCelHxdg1jbaoswDPixisfYB115o4BW R10l7CzOKi/TIxATm5PpB/j3rVV0= X-Google-Smtp-Source: AGHT+IHCFY7bm7trW7utqSY4FXMmC3DFQvhdm3o1bGwu8VwFOBdkVS4gMGc1/SU4dIhEx8JfmEBbd1WzTkUWaN94zeU= X-Received: by 2002:a81:9205:0:b0:607:caee:337d with SMTP id j5-20020a819205000000b00607caee337dmr5059567ywg.3.1708088369494; Fri, 16 Feb 2024 04:59:29 -0800 (PST) MIME-Version: 1.0 References: <20240213041501.2494232-1-hjl.tools@gmail.com> <20240213041501.2494232-3-hjl.tools@gmail.com> <871q9d7wra.fsf@oldenburg.str.redhat.com> <87mss061s0.fsf@oldenburg.str.redhat.com> <984b51c6-920a-40c5-aa1f-182efdd1af92@linaro.org> In-Reply-To: <984b51c6-920a-40c5-aa1f-182efdd1af92@linaro.org> From: "H.J. Lu" Date: Fri, 16 Feb 2024 04:58:53 -0800 Message-ID: Subject: Re: [PATCH v4 2/2] x86: Update _dl_tlsdesc_dynamic to preserve caller-saved registers To: Adhemerval Zanella Netto Cc: Florian Weimer , libc-alpha@sourceware.org, Fangrui Song , "Carlos O'Donell" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3019.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE,URIBL_BLACK autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Fri, Feb 16, 2024 at 4:47=E2=80=AFAM Adhemerval Zanella Netto wrote: > > > > On 16/02/24 09:37, H.J. Lu wrote: > > On Fri, Feb 16, 2024 at 4:20=E2=80=AFAM H.J. Lu w= rote: > >> > >> On Fri, Feb 16, 2024 at 4:18=E2=80=AFAM Florian Weimer wrote: > >>> > >>> * H. J. Lu: > >>> > >>>> On Thu, Feb 15, 2024 at 10:23=E2=80=AFPM Florian Weimer wrote: > >>>>> > >>>>> * Adhemerval Zanella Netto: > >>>>> > >>>>>>> diff --git a/elf/malloc-for-test.map b/elf/malloc-for-test.map > >>>>>>> new file mode 100644 > >>>>>>> index 0000000000..8437cf4346 > >>>>>>> --- /dev/null > >>>>>>> +++ b/elf/malloc-for-test.map > >>>>>>> @@ -0,0 +1,6 @@ > >>>>>>> +GLIBC_2.0 { > >>>>>> > >>>>>> You need to use the correct version to override the malloc: > >>>>>> > >>>>>> $ gdb --args tst-gnu2-tls2 --direct > >>>>>> [...] > >>>>>> (gdb) b apply_tls > >>>>>> (gdb) r > >>>>>> Thread 2 "tst-gnu2-tls2" hit Breakpoint 1, apply_tls (p=3D0x7ffff7= bfee80) at tst-gnu2-tls2mod1.c:25 > >>>>>> 25 { > >>>>>> (gdb) b malloc > >>>>>> Breakpoint 2 at 0x7ffff7ca8ad0: malloc. (3 locations) > >>>>>> (gdb) c > >>>>>> Continuing. > >>>>> > >>>>> Why do we need to set a symbol version here? I think this can be > >>>>> removed. > >>>> > >>>> malloc-for-test.so provides a fake malloc to clobber caller-save > >>>> registers. Since malloc in ld.so has a symbol version, > >>>> > >>>> struct r_found_version version; > >>>> version.name =3D symbol_version_string (libc, GLIBC_2_0); > >>>> version.hidden =3D 0; > >>>> version.hash =3D _dl_elf_hash (version.name); > >>>> version.filename =3D NULL; > >>>> > >>>> void *new_calloc =3D lookup_malloc_symbol (main_map, "calloc", &ve= rsion); > >>>> void *new_free =3D lookup_malloc_symbol (main_map, "free", &versio= n); > >>>> void *new_malloc =3D lookup_malloc_symbol (main_map, "malloc", &ve= rsion); > >>>> void *new_realloc =3D lookup_malloc_symbol (main_map, "realloc", &= version); > >>>> > >>>> malloc in malloc-for-test.so must have the same version. Otherwise, > >>>> it won't be used in the test. > >>> > >>> I thought that unversioned symbols interpose all versioned symbols. = Has > >>> this changed in the dynamic linker? > >> > >> Only for this case. > >> > > > > I was wrong. Version isn't needed. Will fix it. > > > > Indeed, but I think we also improve the register check testing since just= clobbering > on malloc does not really provide much coverage. Why? The slow path will always call malloc in malloc-for-test.so. We can clobber any caller-save registers we need. Without malloc-for-test.so, the test doesn't fail for i386 since malloc in libc.so doesn't use any vector registers. --=20 H.J.