From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by sourceware.org (Postfix) with ESMTPS id 4ECBB385DC0F for ; Tue, 14 Apr 2020 13:28:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4ECBB385DC0F Received: by mail-pf1-x442.google.com with SMTP id w65so37655pfc.12 for ; Tue, 14 Apr 2020 06:28:59 -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:subject:date:message-id:mime-version :content-transfer-encoding; bh=v7oVafh/Hj7jGlQT7KyLHV2QzU0BRckK9M+XTLSPJlQ=; b=HMZdERyzezqXw/Rn9XAFcKrAeTdfjvbdriN47isvLczZiFTySIT+IgAT9meCJbkKvO 5WTE27U2Udc9D5XvmC4Q5XFrEw6/EitxJnVMm1WoEcbQGpYcoGOcCLjCbL8vBmDQXdDO W3vSBmczSZD1YSgXgtKE7fnzhaBMO3vkSuCuEOEJ5QEuQmDbc0S90aNH+FLE1Hfzyeu5 3ByuCxfdgkNH39NGbm8IyqeI/9Ch6IXuBwqcIaR+P+jlYVa0QEeTDSxxhd/daFYIoI5L uaqKShhicH29hLNOLSGoZ7EpLnPfL1EMI6iIEJENelNaUR7791JPV9APIa8lGTeUewJK KC3w== X-Gm-Message-State: AGi0PuYC/Tu659WGCQetCw36aYjeuMXn1Q2q6ChWjtv67SuBMdhrkA2m B9oaow0KeRsyLWAowloddM8szYIZ X-Google-Smtp-Source: APiQypIW2WWgEuInJGATMwsYCCcYyqz749QfxHADSxIvPtMDk66TMY1Zl8Jp5vbabtd41bzGRBjyTA== X-Received: by 2002:a63:7d19:: with SMTP id y25mr21303203pgc.78.1586870938257; Tue, 14 Apr 2020 06:28:58 -0700 (PDT) Received: from gnu-cfl-2.localdomain (c-69-181-90-243.hsd1.ca.comcast.net. [69.181.90.243]) by smtp.gmail.com with ESMTPSA id p62sm3724776pfb.93.2020.04.14.06.28.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Apr 2020 06:28:57 -0700 (PDT) Received: from gnu-cfl-2.localdomain (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id BD071C045D for ; Tue, 14 Apr 2020 06:28:56 -0700 (PDT) From: "H.J. Lu" To: binutils@sourceware.org Subject: [PATCH 1/2] readelf: Warn if PT_DYNAMIC segment doesn't match .dynamic section Date: Tue, 14 Apr 2020 06:28:55 -0700 Message-Id: <20200414132856.535909-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.25.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-28.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, 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 X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Apr 2020 13:29:00 -0000 The PT_DYNAMIC segment, which is used by the run-time loader, must exactly match the .dynamic section. PR binutils/25809 * readelf.c (process_program_headers): Warn if the PT_DYNAMIC segment doesn't match the .dynamic section. --- binutils/readelf.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/binutils/readelf.c b/binutils/readelf.c index 535d47a58e..91e47887e7 100644 --- a/binutils/readelf.c +++ b/binutils/readelf.c @@ -5337,13 +5337,12 @@ process_program_headers (Filedata * filedata) dynamic_addr = sec->sh_offset; dynamic_size = sec->sh_size; - if (dynamic_addr < segment->p_offset - || dynamic_addr > segment->p_offset + segment->p_filesz) - warn (_("the .dynamic section is not contained" - " within the dynamic segment\n")); - else if (dynamic_addr > segment->p_offset) - warn (_("the .dynamic section is not the first section" - " in the dynamic segment.\n")); + /* The PT_DYNAMIC segment, which is used by the run-time + loader, must exactly match the .dynamic section. */ + if (dynamic_addr != segment->p_offset + || dynamic_size != segment->p_filesz) + warn (_("the .dynamic section doesn't match the " + "dynamic segment\n")); } /* PR binutils/17512: Avoid corrupt dynamic section info in the -- 2.25.2