Skip to content

Commit 0173da5

Browse files
committed
Support section data lookup within static libraries
1 parent 8e3012c commit 0173da5

File tree

5 files changed

+47
-10
lines changed

5 files changed

+47
-10
lines changed

core/org.eclipse.cdt.core/.settings/.api_filters

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,12 @@
1414
</message_arguments>
1515
</filter>
1616
</resource>
17+
<resource path="utils/org/eclipse/cdt/utils/coff/Coff64.java" type="org.eclipse.cdt.utils.coff.Coff64$Symbol">
18+
<filter id="336658481">
19+
<message_arguments>
20+
<message_argument value="org.eclipse.cdt.utils.coff.Coff64.Symbol"/>
21+
<message_argument value="SC_EXTERNAL"/>
22+
</message_arguments>
23+
</filter>
24+
</resource>
1725
</component>

core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/Coff64.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2023 Space Codesign Systems and others.
2+
* Copyright (c) 2000, 2024 Space Codesign Systems and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -13,6 +13,7 @@
1313
* QNX Software Systems - Initial Coff class
1414
* Alexander Fedorov (ArSysOp) - Bug 561992
1515
* John Dallaway - Provide additional section header flags (#652)
16+
* John Dallaway - Support offset into archive file (#630)
1617
*******************************************************************************/
1718
package org.eclipse.cdt.utils.coff;
1819

@@ -329,9 +330,17 @@ file, a new function (as
329330

330331
RandomAccessFile sfile;
331332

332-
public SectionHeader(RandomAccessFile file, long offset) throws IOException {
333+
private final long objOffset; // the offset of this binary object within the file (eg archive file)
334+
335+
public SectionHeader(RandomAccessFile file, long hdrOffset) throws IOException {
336+
this(file, 0, hdrOffset);
337+
}
338+
339+
/** @since 8.4 */
340+
public SectionHeader(RandomAccessFile file, long objOffset, long hdrOffset) throws IOException {
333341
sfile = file;
334-
file.seek(offset);
342+
this.objOffset = objOffset;
343+
file.seek(hdrOffset + objOffset);
335344
byte[] hdr = new byte[SCNHSZ];
336345
file.readFully(hdr);
337346
ReadMemoryAccess memory = new ReadMemoryAccess(hdr, true);
@@ -409,7 +418,8 @@ public String toString() {
409418
* @since 5.1
410419
*/
411420
public ByteBuffer mapSectionData() throws IOException {
412-
return sfile.getChannel().map(MapMode.READ_ONLY, s_scnptr, s_paddr).load().asReadOnlyBuffer();
421+
long size = s_paddr == 0 ? s_size : s_paddr;
422+
return sfile.getChannel().map(MapMode.READ_ONLY, s_scnptr + objOffset, size).load().asReadOnlyBuffer();
413423
}
414424
}
415425

@@ -525,6 +535,9 @@ public static class Symbol {
525535
/** @since 5.3 */
526536
public final static int T_LNGDBL = 0x16; /* -1 0000 long double (special case bit pattern) */
527537

538+
/** @since 8.4 */
539+
public static final int SC_EXTERNAL = 2; /* external symbol storage class */
540+
528541
public byte[] _n_name = new byte[SYMNMLEN]; /* Symbol name, or pointer into
529542
string table if symbol name
530543
is greater than SYMNMLEN. */

core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/PE64.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2023 Space Codesign Systems and others.
2+
* Copyright (c) 2000, 2024 Space Codesign Systems and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -762,7 +762,7 @@ public SectionHeader[] getSectionHeaders() throws IOException {
762762
}
763763
offset += FileHeader.FILHSZ + fileHeader.f_opthdr;
764764
for (int i = 0; i < scnhdrs.length; i++, offset += SectionHeader.SCNHSZ) {
765-
scnhdrs[i] = new SectionHeader(accessFile, offset + peOffset);
765+
scnhdrs[i] = new SectionHeader(accessFile, peOffset, offset);
766766
}
767767
}
768768
return scnhdrs;

core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/Elf.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2016 QNX Software Systems and others.
2+
* Copyright (c) 2000, 2024 QNX Software Systems and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -11,6 +11,7 @@
1111
* Contributors:
1212
* QNX Software Systems - initial API and implementation
1313
* Markus Schorn (Wind River Systems)
14+
* John Dallaway - Support offset into archive file (#630)
1415
*******************************************************************************/
1516
package org.eclipse.cdt.utils.elf;
1617

@@ -333,12 +334,23 @@ public class Section {
333334
public long sh_addralign;
334335
public long sh_entsize;
335336

337+
private final long objOffset; // the offset of this binary object within the file (eg archive file)
338+
339+
public Section() {
340+
this(0);
341+
}
342+
343+
/** @since 8.4 */
344+
public Section(long objOffset) {
345+
this.objOffset = objOffset;
346+
}
347+
336348
/**
337349
* @since 5.1
338350
*/
339351
public ByteBuffer mapSectionData() throws IOException {
340352
makeSureNotCompressed();
341-
return efile.getChannel().map(MapMode.READ_ONLY, sh_offset, sh_size).load().asReadOnlyBuffer();
353+
return efile.getChannel().map(MapMode.READ_ONLY, sh_offset + objOffset, sh_size).load().asReadOnlyBuffer();
342354
}
343355

344356
public byte[] loadSectionData() throws IOException {
@@ -1037,7 +1049,7 @@ public Section[] getSections() throws IOException {
10371049
sections = new Section[length];
10381050
for (int i = 0; i < length; i++) {
10391051
efile.seek(ehdr.e_shoff + i * (ehdr.e_shentsize & 0xffff)); // unsigned short
1040-
sections[i] = new Section();
1052+
sections[i] = new Section(elfOffset);
10411053
sections[i].sh_name = efile.readIntE();
10421054
sections[i].sh_type = efile.readIntE();
10431055
switch (ehdr.e_ident[ELFhdr.EI_CLASS]) {

core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ElfBinaryObject.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2015 QNX Software Systems and others.
2+
* Copyright (c) 2000, 2024 QNX Software Systems and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -10,6 +10,7 @@
1010
*
1111
* Contributors:
1212
* QNX Software Systems - Initial API and implementation
13+
* John Dallaway - Fix archive header processing (#630)
1314
*******************************************************************************/
1415
package org.eclipse.cdt.utils.elf.parser;
1516

@@ -182,6 +183,9 @@ protected void addSymbols(Elf.Symbol[] array, int type, List<Symbol> list) {
182183
public <T> T getAdapter(Class<T> adapter) {
183184
if (adapter.equals(Elf.class)) {
184185
try {
186+
if (header != null) {
187+
return (T) new Elf(getPath().toOSString(), header.getObjectDataOffset());
188+
}
185189
return (T) new Elf(getPath().toOSString());
186190
} catch (IOException e) {
187191
}

0 commit comments

Comments
 (0)