From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) by sourceware.org (Postfix) with ESMTPS id C4D74393BC18 for ; Mon, 3 May 2021 16:20:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C4D74393BC18 Received: by mail-lj1-x230.google.com with SMTP id d15so7448170ljo.12 for ; Mon, 03 May 2021 09:20:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=CQ3DQXE85XkA2hkZXGUwxfnMSX3ZxZ4jU7vkd2L/i0w=; b=GkbpUooge3bc9gSiFrYmYcbM3hMXt+IClQlwTDO1ZD2w02GDm0DkIFcoXkucTSvqkX cskfyfREM0w6JaV0jNpnICjvfqcDqSouv3ynks0/aAchvkltjnM30eWcS/xO6UCHimf6 nyco3gGPRzst1IjVnzurP4kjszNe3AqLm+EhmXwE1/ReiVkbBQn6IuhPnt/BGDtaq+rn yu4ujjy37CKAgDSrxEzZUr+E2I/83bNevl2oiURtAvA1qwkaHi7bwcVciLtA/U84FiH+ CKBO4uRD68hoaLXYcISqNU93TMLbjb3M3FDdProIcSq9JVtbtqjwpWgBmyoly15IgRKY UaIQ== X-Gm-Message-State: AOAM533qhZMLc3VlUolZpcvHy7nRlMnQPklpB2rENIPwUewWO+hUtDvM rpym2i3bZA3SEz8aj2JTooNf0RJ7jZLlnuf6Vje99YyNQtk= X-Google-Smtp-Source: ABdhPJz430Ax9vEnSdc5ZHHxTQjZcSKHgJCI0NSCpKhWvACeuy7RKZA0fwkcalk8U4ueCA4JXfAJM/BptWcPm2g3GmA= X-Received: by 2002:a2e:9546:: with SMTP id t6mr14042806ljh.10.1620058835434; Mon, 03 May 2021 09:20:35 -0700 (PDT) MIME-Version: 1.0 From: Fengkai Sun Date: Tue, 4 May 2021 00:20:24 +0800 Message-ID: Subject: The correctness of dlopen-ing a PIE executable To: libc-help@sourceware.org X-Spam-Status: No, score=-0.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: libc-help@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-help mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 03 May 2021 16:20:38 -0000 Hi list, I'm very interested in the idea of dynamically loading a PIE executable using dlopen, and I found a patch at: https://sourceware.org/bugzilla/show_bug.cgi?id=11754 However, as the comment( https://sourceware.org/bugzilla/show_bug.cgi?id=11754#c13) below suggests, this is a bad idea. So glibc explicitly forbids it in dl-load.c. But in this question: https://stackoverflow.com/questions/64659713/why-does-dynamically-loading-of-pies-no-longer-work-in-glibc, the author shows that: * recompile the executable using -fPIC, which eliminates relocation type R_X86_64_COPY, will fix the bug in https://sourceware.org/bugzilla/show_bug.cgi?id=11754#c15 * constructors, relocations, and thread local variables seem to work OK I know that the reasons the author above listed are probably not exhaustive, so I want to make it clear that is there any irrecoverable problem that prevents dlopen to load PIE executable correctly?(suppose we force the executable enable -fPIC ) If so, how will a modified loader manage to solve that, as mentioned in https://sourceware.org/bugzilla/show_bug.cgi?id=11754#c16 ? Thank you very much. Best, Fengkai