mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Support section data lookup within static libraries
This commit is contained in:
parent
8e3012c902
commit
0173da5325
5 changed files with 47 additions and 10 deletions
|
@ -14,4 +14,12 @@
|
||||||
</message_arguments>
|
</message_arguments>
|
||||||
</filter>
|
</filter>
|
||||||
</resource>
|
</resource>
|
||||||
|
<resource path="utils/org/eclipse/cdt/utils/coff/Coff64.java" type="org.eclipse.cdt.utils.coff.Coff64$Symbol">
|
||||||
|
<filter id="336658481">
|
||||||
|
<message_arguments>
|
||||||
|
<message_argument value="org.eclipse.cdt.utils.coff.Coff64.Symbol"/>
|
||||||
|
<message_argument value="SC_EXTERNAL"/>
|
||||||
|
</message_arguments>
|
||||||
|
</filter>
|
||||||
|
</resource>
|
||||||
</component>
|
</component>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2000, 2023 Space Codesign Systems and others.
|
* Copyright (c) 2000, 2024 Space Codesign Systems and others.
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials
|
* This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License 2.0
|
* are made available under the terms of the Eclipse Public License 2.0
|
||||||
|
@ -13,6 +13,7 @@
|
||||||
* QNX Software Systems - Initial Coff class
|
* QNX Software Systems - Initial Coff class
|
||||||
* Alexander Fedorov (ArSysOp) - Bug 561992
|
* Alexander Fedorov (ArSysOp) - Bug 561992
|
||||||
* John Dallaway - Provide additional section header flags (#652)
|
* John Dallaway - Provide additional section header flags (#652)
|
||||||
|
* John Dallaway - Support offset into archive file (#630)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.utils.coff;
|
package org.eclipse.cdt.utils.coff;
|
||||||
|
|
||||||
|
@ -329,9 +330,17 @@ public class Coff64 {
|
||||||
|
|
||||||
RandomAccessFile sfile;
|
RandomAccessFile sfile;
|
||||||
|
|
||||||
public SectionHeader(RandomAccessFile file, long offset) throws IOException {
|
private final long objOffset; // the offset of this binary object within the file (eg archive file)
|
||||||
|
|
||||||
|
public SectionHeader(RandomAccessFile file, long hdrOffset) throws IOException {
|
||||||
|
this(file, 0, hdrOffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @since 8.4 */
|
||||||
|
public SectionHeader(RandomAccessFile file, long objOffset, long hdrOffset) throws IOException {
|
||||||
sfile = file;
|
sfile = file;
|
||||||
file.seek(offset);
|
this.objOffset = objOffset;
|
||||||
|
file.seek(hdrOffset + objOffset);
|
||||||
byte[] hdr = new byte[SCNHSZ];
|
byte[] hdr = new byte[SCNHSZ];
|
||||||
file.readFully(hdr);
|
file.readFully(hdr);
|
||||||
ReadMemoryAccess memory = new ReadMemoryAccess(hdr, true);
|
ReadMemoryAccess memory = new ReadMemoryAccess(hdr, true);
|
||||||
|
@ -409,7 +418,8 @@ public class Coff64 {
|
||||||
* @since 5.1
|
* @since 5.1
|
||||||
*/
|
*/
|
||||||
public ByteBuffer mapSectionData() throws IOException {
|
public ByteBuffer mapSectionData() throws IOException {
|
||||||
return sfile.getChannel().map(MapMode.READ_ONLY, s_scnptr, s_paddr).load().asReadOnlyBuffer();
|
long size = s_paddr == 0 ? s_size : s_paddr;
|
||||||
|
return sfile.getChannel().map(MapMode.READ_ONLY, s_scnptr + objOffset, size).load().asReadOnlyBuffer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -525,6 +535,9 @@ public class Coff64 {
|
||||||
/** @since 5.3 */
|
/** @since 5.3 */
|
||||||
public final static int T_LNGDBL = 0x16; /* -1 0000 long double (special case bit pattern) */
|
public final static int T_LNGDBL = 0x16; /* -1 0000 long double (special case bit pattern) */
|
||||||
|
|
||||||
|
/** @since 8.4 */
|
||||||
|
public static final int SC_EXTERNAL = 2; /* external symbol storage class */
|
||||||
|
|
||||||
public byte[] _n_name = new byte[SYMNMLEN]; /* Symbol name, or pointer into
|
public byte[] _n_name = new byte[SYMNMLEN]; /* Symbol name, or pointer into
|
||||||
string table if symbol name
|
string table if symbol name
|
||||||
is greater than SYMNMLEN. */
|
is greater than SYMNMLEN. */
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2000, 2023 Space Codesign Systems and others.
|
* Copyright (c) 2000, 2024 Space Codesign Systems and others.
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials
|
* This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License 2.0
|
* are made available under the terms of the Eclipse Public License 2.0
|
||||||
|
@ -762,7 +762,7 @@ public class PE64 implements AutoCloseable {
|
||||||
}
|
}
|
||||||
offset += FileHeader.FILHSZ + fileHeader.f_opthdr;
|
offset += FileHeader.FILHSZ + fileHeader.f_opthdr;
|
||||||
for (int i = 0; i < scnhdrs.length; i++, offset += SectionHeader.SCNHSZ) {
|
for (int i = 0; i < scnhdrs.length; i++, offset += SectionHeader.SCNHSZ) {
|
||||||
scnhdrs[i] = new SectionHeader(accessFile, offset + peOffset);
|
scnhdrs[i] = new SectionHeader(accessFile, peOffset, offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return scnhdrs;
|
return scnhdrs;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2000, 2016 QNX Software Systems and others.
|
* Copyright (c) 2000, 2024 QNX Software Systems and others.
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials
|
* This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License 2.0
|
* are made available under the terms of the Eclipse Public License 2.0
|
||||||
|
@ -11,6 +11,7 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX Software Systems - initial API and implementation
|
* QNX Software Systems - initial API and implementation
|
||||||
* Markus Schorn (Wind River Systems)
|
* Markus Schorn (Wind River Systems)
|
||||||
|
* John Dallaway - Support offset into archive file (#630)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.utils.elf;
|
package org.eclipse.cdt.utils.elf;
|
||||||
|
|
||||||
|
@ -333,12 +334,23 @@ public class Elf implements AutoCloseable {
|
||||||
public long sh_addralign;
|
public long sh_addralign;
|
||||||
public long sh_entsize;
|
public long sh_entsize;
|
||||||
|
|
||||||
|
private final long objOffset; // the offset of this binary object within the file (eg archive file)
|
||||||
|
|
||||||
|
public Section() {
|
||||||
|
this(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @since 8.4 */
|
||||||
|
public Section(long objOffset) {
|
||||||
|
this.objOffset = objOffset;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since 5.1
|
* @since 5.1
|
||||||
*/
|
*/
|
||||||
public ByteBuffer mapSectionData() throws IOException {
|
public ByteBuffer mapSectionData() throws IOException {
|
||||||
makeSureNotCompressed();
|
makeSureNotCompressed();
|
||||||
return efile.getChannel().map(MapMode.READ_ONLY, sh_offset, sh_size).load().asReadOnlyBuffer();
|
return efile.getChannel().map(MapMode.READ_ONLY, sh_offset + objOffset, sh_size).load().asReadOnlyBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] loadSectionData() throws IOException {
|
public byte[] loadSectionData() throws IOException {
|
||||||
|
@ -1037,7 +1049,7 @@ public class Elf implements AutoCloseable {
|
||||||
sections = new Section[length];
|
sections = new Section[length];
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
efile.seek(ehdr.e_shoff + i * (ehdr.e_shentsize & 0xffff)); // unsigned short
|
efile.seek(ehdr.e_shoff + i * (ehdr.e_shentsize & 0xffff)); // unsigned short
|
||||||
sections[i] = new Section();
|
sections[i] = new Section(elfOffset);
|
||||||
sections[i].sh_name = efile.readIntE();
|
sections[i].sh_name = efile.readIntE();
|
||||||
sections[i].sh_type = efile.readIntE();
|
sections[i].sh_type = efile.readIntE();
|
||||||
switch (ehdr.e_ident[ELFhdr.EI_CLASS]) {
|
switch (ehdr.e_ident[ELFhdr.EI_CLASS]) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2000, 2015 QNX Software Systems and others.
|
* Copyright (c) 2000, 2024 QNX Software Systems and others.
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials
|
* This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License 2.0
|
* are made available under the terms of the Eclipse Public License 2.0
|
||||||
|
@ -10,6 +10,7 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX Software Systems - Initial API and implementation
|
* QNX Software Systems - Initial API and implementation
|
||||||
|
* John Dallaway - Fix archive header processing (#630)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.utils.elf.parser;
|
package org.eclipse.cdt.utils.elf.parser;
|
||||||
|
|
||||||
|
@ -182,6 +183,9 @@ public class ElfBinaryObject extends BinaryObjectAdapter {
|
||||||
public <T> T getAdapter(Class<T> adapter) {
|
public <T> T getAdapter(Class<T> adapter) {
|
||||||
if (adapter.equals(Elf.class)) {
|
if (adapter.equals(Elf.class)) {
|
||||||
try {
|
try {
|
||||||
|
if (header != null) {
|
||||||
|
return (T) new Elf(getPath().toOSString(), header.getObjectDataOffset());
|
||||||
|
}
|
||||||
return (T) new Elf(getPath().toOSString());
|
return (T) new Elf(getPath().toOSString());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue