From patchwork Mon Aug 30 17:38:42 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: 44810 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 929CC385702D for ; Mon, 30 Aug 2021 17:40:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 929CC385702D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1630345219; bh=HKknABY3wJP2OBYMil3aStfj/UFOCHo6UUyPjLcFNtw=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=JEJk88/ChbkQYAp2079h0Dv8R1YgD5e+KlVxzBZuVjYum7uIS2Q/NsVrLND7vVctY 5tFevNzvxgCaYNu9Pw9eW5L2KwEVAOS2imo43nFAly4ws51nyXqvwBRgecEC3Ibq9e MLjrDm1YjFIDEqwNBFvNMLYCW6KYpCETFcanqD1g= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by sourceware.org (Postfix) with ESMTPS id 0A70E385800E; Mon, 30 Aug 2021 17:38:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0A70E385800E Received: by mail-pj1-x102a.google.com with SMTP id w19-20020a17090aaf9300b00191e6d10a19so493845pjq.1; Mon, 30 Aug 2021 10:38:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=HKknABY3wJP2OBYMil3aStfj/UFOCHo6UUyPjLcFNtw=; b=noKnhcJVIJ3nypHHbDo8G7coO7cxoSgejH+2RkeEG2mUlotaKnacNh57nh9xtpP8Xs pCUpHh/LNkva6C4SJwbidMaUMgi7u7obEKORLUDy6oY8Lj0DLZ+e5vQUoIinIkxwWZ2R SCrQxQEldGMS5iMmK/VeLz/p6LgvOfQisSLY1cZp9e+dKp7Un/3WQ1cfNSENGN1ZMGpT 3iKNWzGULw7tKpZSPI0UYEVHzxzSCfy5wzZ0DXPecjk8zuKWaxe0zEbgq51CU9uUudeA ikzuUlVVB/ioB6iueWlohq/XpXFWdE3wc56WC9yQMp3W3EbvXA+sHb0aBg8N0ZzlK14k 0Few== X-Gm-Message-State: AOAM533UGgS+orz9aihM1ToORitCdnRcSVII3kzLYl3TwO9iVIVSxygY mIZ5OqSJHrC7mmkLN7k8Bz8= X-Google-Smtp-Source: ABdhPJyl4qbN60qz/SIJWpnvODAe5fun7YSaletg9mVzV27OyorALRyyxIFOdxhXxzrgQliQWFXIHw== X-Received: by 2002:a17:90a:2fc2:: with SMTP id n2mr233711pjm.112.1630345126090; Mon, 30 Aug 2021 10:38:46 -0700 (PDT) Received: from gnu-cfl-2.localdomain ([172.58.38.240]) by smtp.gmail.com with ESMTPSA id x19sm17917703pgk.37.2021.08.30.10.38.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Aug 2021 10:38:45 -0700 (PDT) Received: from gnu-cfl-2.. (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id 84121C006C; Mon, 30 Aug 2021 10:38:44 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v6 0/2] Extend struct r_debug to support multiple namespaces Date: Mon, 30 Aug 2021 10:38:42 -0700 Message-Id: <20210830173844.458727-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Spam-Status: No, score=-3023.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, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=no 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 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. 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. Remove the empty namespace from the namespace linked list and clear its r_version field. 4. Add the new namespace, whose r_version field is 0, to the namespace linked list. 5. Initialize the r_debug_extended structure only if its r_version field is 0 and update its r_map field if it is NULL. 6. Add a hidden symbol, _r_debug_extended, for struct r_debug_extended. 7. 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. 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. 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. Remove the empty namespace from the namespace linked list and clear its r_version field. 4. Add the new namespace, whose r_version field is 0, to the namespace linked list. 5. Initialize the r_debug_extended structure only if its r_version field is 0 and update its r_map field if it is NULL. 6. Add a hidden symbol, _r_debug_extended, for struct r_debug_extended. 7. 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. H.J. Lu (2): Add declare_object_symbol_alias for assembly codes [BZ #28128] Extend struct r_debug to support multiple namespaces NEWS | 9 ++++- csu/Makefile | 3 ++ csu/rtld-sizes.sym | 4 ++ elf/Makefile | 24 +++++++++++- elf/dl-close.c | 21 ++++++++++ elf/dl-debug-symbols-gen.c | 24 ++++++++++++ elf/dl-debug-symbols.S | 37 ++++++++++++++++++ elf/dl-debug.c | 46 ++++++++++++---------- elf/dl-reloc-static-pie.c | 2 +- elf/link.h | 36 ++++++++++++----- elf/rtld-debugger-interface.txt | 14 +++++++ elf/rtld.c | 2 +- elf/tst-dlmopen4.c | 68 +++++++++++++++++++++++++++++++++ include/libc-symbols.h | 12 +++--- include/link.h | 4 ++ sysdeps/generic/ldsodefs.h | 8 ++-- 16 files changed, 270 insertions(+), 44 deletions(-) create mode 100644 csu/rtld-sizes.sym create mode 100644 elf/dl-debug-symbols-gen.c create mode 100644 elf/dl-debug-symbols.S create mode 100644 elf/tst-dlmopen4.c