[binutils-gdb] libiberty, Darwin: Fix handling of file offsets.

Alan Modra via Binutils-cvs <[email protected]>
Newsgroups gmane.comp.gnu.binutils.cvs
Message-ID <20260308220459.E07824BA2E14__37785.6475462735$1773007509$gmane$org@sourceware.org>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=96c87c6dd55c38519ad168230d0893797b62fd52

commit 96c87c6dd55c38519ad168230d0893797b62fd52
Author: Iain Sandoe <[email protected]>
Date:   Tue Feb 24 11:44:27 2026 +0000

    libiberty, Darwin: Fix handling of file offsets.
    
    In the case where a Mach-O object is embedded inside some container
    (e.g. an archive) we must account the offset from the start of that
    container when reading.  In most cases, this has been done correctly.
    However, we were missing the case for reading segment data.  This
    only showed up once we tried using archives (since regular Mach-O
    objects start at the begining of the file).
    
    Fixed thus.
    
    libiberty/ChangeLog:
    
            * simple-object-mach-o.c
            (simple_object_mach_o_segment): Account for the offset of
            this Mach-O object from the start of any container.
    
    Signed-off-by: Iain Sandoe <[email protected]>

Diff:
---
 libiberty/simple-object-mach-o.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libiberty/simple-object-mach-o.c b/libiberty/simple-object-mach-o.c
index 3e81d6f908a..0897a3edf7d 100644
--- a/libiberty/simple-object-mach-o.c
+++ b/libiberty/simple-object-mach-o.c
@@ -464,7 +464,8 @@ simple_object_mach_o_segment (simple_object_read *sobj, off_t offset,
   /* Fetch the section headers from the segment command.  */
 
   secdata = XNEWVEC (unsigned char, nsects * sechdrsize);
-  if (!simple_object_internal_read (sobj->descriptor, offset + seghdrsize,
+  if (!simple_object_internal_read (sobj->descriptor,
+				    sobj->offset + offset + seghdrsize,
 				    secdata, nsects * sechdrsize, errmsg, err))
     {
       XDELETEVEC (secdata);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.