From patchwork Fri Sep 10 20:12:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 44925 Return-Path: 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 B0452385840D for ; Fri, 10 Sep 2021 20:13:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B0452385840D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1631304825; bh=ZIEKXdi3AZjin/WzHpDNRzbDGLYtpegY3wOaPcS22qQ=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=cPgTx0S1GoxMazR262hPE3MyHhukHB8nq2/8mQmwJtZZBrlmZdaig291GAnb0C1Dp xMo+G8iUrfLsOBh81D079akxzMhemZiZ45euMs0oLR/Muwrj0SV3kmNo0xXPJNt9UV eDwatMqBHFeruZq73Q08lIsxCIlBqqbR7rt8Cnf4= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by sourceware.org (Postfix) with ESMTPS id B7B063858D29; Fri, 10 Sep 2021 20:12:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B7B063858D29 Received: by mail-pl1-x62c.google.com with SMTP id e7so1860606plh.8; Fri, 10 Sep 2021 13:12:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ZIEKXdi3AZjin/WzHpDNRzbDGLYtpegY3wOaPcS22qQ=; b=zG/8s0E8fFUqaGeX5ukD8dsVn5aPuEuc61abdpA7EyWMkJX6wlBE7sgXVjDSoAWvzP hdMPAWLfAXGkpiSsa14ci6gXoIc0uH7MoFsXG7uXTG/UZGxCNyNI7v20ZwEjB5oQCDB0 Td6J8StEJYJqx+lhzgDia8UB+jHKJfvt1Mn7fc95XcvtWjydEtbVH6O0XNVcWJLePzSl 6+9iuSNBg/t6PkfG1SJ8biM1paBSRQsofJHFq/0IcJYJWjM8GxgoTZt8et+HMXfOTflM 8970+5ePudkz3rOcDXFKs8Xb1q4l3uV30eAsyjbJTzcVjMfPfdWk9rl/vM4HdMDG95Bz GmCw== X-Gm-Message-State: AOAM531zQPGUSzyV8AcHYBN56GDGWNG8pvoCoGt0SNLamgNGD8qvBClM FBzbpHOu9fHsPt1u3U16d3o= X-Google-Smtp-Source: ABdhPJxTge+ZSL7KdGNJBQqFmzV0QL2Q2+v1TNU/Av4LoeUZWRxYDqJ5/QiAZrVU8FvT3XF8BmU4bw== X-Received: by 2002:a17:90a:1a45:: with SMTP id 5mr11260740pjl.212.1631304741889; Fri, 10 Sep 2021 13:12:21 -0700 (PDT) Received: from gnu-cfl-2.localdomain ([172.56.39.243]) by smtp.gmail.com with ESMTPSA id j128sm5945748pfd.38.2021.09.10.13.12.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Sep 2021 13:12:21 -0700 (PDT) Received: from gnu-cfl-2.. (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id 8225AC0080; Fri, 10 Sep 2021 13:12:19 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v9 0/1] Extend struct r_debug to support multiple namespaces Date: Fri, 10 Sep 2021 13:12:18 -0700 Message-Id: <20210910201219.156682-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Spam-Status: No, score=-3026.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: "H.J. Lu via Libc-alpha" From: "H.J. Lu" Reply-To: "H.J. Lu" Cc: Florian Weimer , gdb@sourceware.org, libc-coord@lists.openwall.com Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Changes in the v9 patch: 1. Remove compatibility in comments for _r_debug. 2. Update rtld-debugger-interface.txt for active namespace. 3. Update tst-dlmopen4.c to verify r_version == 1 before dlmopen. 4. Use TEST_COMPARE and TEST_COMPARE_STRING in tst-dlmopen4.c. Changes in the v8 patch: 1. Check base.r_brk == 0, instead of r_next == NULL, to decide if a namespace has been initialized. r_next can be NULL after initialization, but base.r_brk must be non-zero after initialization. Changes in the v7 patch: 1. Rewrite dl-debug-symbols.S and remove dl-debug-compat-symbols.c. 2. Bump r_version to 2 only when multiple namespaces are used. 3. Verify r_version == 1 without multiple namespaces. 4. Keep the empty (unused) namespace on the namespace linked list. 5. Use atomic_store_release to update r_version and r_next. 6. Add _dl_debug_update without adding the namespace to the namespace linked list. Changes in the v6 patch: 1. Add comments for dl-debug-compat-symbols.[o|os] usage. Changes in the v5 patch: 1. Use struct r_debug as the base for struct r_debug_extended. 2. Keep _dl_debug_initialize return type. Changes in the v4 patch: 1. Improve the empty namespace removal from the namespace linked list. 2. Check r_version == 0 for the unused namespace. Changes in the v3 patch: 1. Remove the empty namespace from the namespace linked list. 2. Properly add the new namespace to the linked list. Changes in the v2 patch: 1. Bump r_version to 2. 2. Don't add DT_DEBUGSZ. 3. Add struct r_debug_extended to extend struct r_debug. 4. Don't update the r_state field in the copy of _r_debug in executable since it is not consumed by the program. --- Glibc does not provide an interface for debugger to access libraries loaded in multiple namespaces via dlmopen. The current rtld-debugger interface is described in the file: elf/rtld-debugger-interface.txt under the "Standard debugger interface" heading. This interface only provides access to the first link-map (LM_ID_BASE). 1. Bump r_version to 2 when multiple namespaces are used. This triggers the GDB bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28236 2. Add struct r_debug_extended to extend struct r_debug into a linked-list, where each element correlates to an unique namespace. 3. Initialize the r_debug_extended structure. Bump r_version to 2 for the new namespace and add the new namespace to the namespace linked list. 4. Add _dl_debug_update to return the address of struct r_debug' of a namespace. 5. Add a hidden symbol, _r_debug_extended, for struct r_debug_extended. 6. Provide the compatibility symbol, _r_debug, with size of struct r_debug, as an alise of _r_debug_extended, for programs which reference _r_debug. This fixes BZ #15971. H.J. Lu (1): Extend struct r_debug to support multiple namespaces [BZ #15971] NEWS | 11 ++++- csu/Makefile | 3 ++ csu/rtld-sizes.sym | 6 +++ elf/Makefile | 7 +++- elf/dl-close.c | 2 +- elf/dl-debug-symbols.S | 37 +++++++++++++++++ elf/dl-debug.c | 72 ++++++++++++++++++++++++--------- elf/dl-load.c | 2 +- elf/dl-open.c | 10 ++--- elf/dl-reloc-static-pie.c | 2 +- elf/link.h | 35 +++++++++++----- elf/rtld-debugger-interface.txt | 15 +++++++ elf/rtld.c | 4 +- elf/tst-dlmopen4.c | 72 +++++++++++++++++++++++++++++++++ include/link.h | 4 ++ sysdeps/generic/ldsodefs.h | 12 ++++-- 16 files changed, 249 insertions(+), 45 deletions(-) create mode 100644 csu/rtld-sizes.sym create mode 100644 elf/dl-debug-symbols.S create mode 100644 elf/tst-dlmopen4.c