]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libiberty, Darwin: Fix handling of file offsets.
authorIain Sandoe <iain@sandoe.co.uk>
Tue, 24 Feb 2026 11:44:27 +0000 (11:44 +0000)
committerIain Sandoe <iain@sandoe.co.uk>
Wed, 25 Feb 2026 06:44:49 +0000 (06:44 +0000)
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 <iain@sandoe.co.uk>
libiberty/simple-object-mach-o.c

index 3e81d6f908a0a2596ec807a029df208429661650..0897a3edf7d5efc46145e0f41b6b31ce32e2ed3d 100644 (file)
@@ -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);