Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GNU PE64 binary parser for MinGW GCC toolchain #365

Merged
merged 1 commit into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.cdt.managedbuilder.core; singleton:=true
Bundle-Version: 9.5.0.qualifier
Bundle-Version: 9.5.100.qualifier
Bundle-Activator: org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ Additional special types exist to flag options of special relevance to the build
<attribute name="binaryParser" type="string">
<annotation>
<documentation>
Set this to the ID of the binary parser for the output format of your target. Currently there are only 2 choices: org.eclipse.cdt.core.ELF for *nix targets, and &quot;org.eclipse.cdt.core.PE64&quot; for targets that build for Windows, like Cygwin.
Set this to the ID of the binary parser for the output format of your target. Currently there are ELF parsers for *nix and many embedded targets, and PE64 parsers for Windows targets. Alternative versions of these parsers provide additional capabilities for GNU toolchains only.
</documentation>
</annotation>
</attribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.cdt.managedbuilder.gnu.ui; singleton:=true
Bundle-Version: 8.5.0.qualifier
Bundle-Version: 8.5.100.qualifier
Bundle-Activator: org.eclipse.cdt.managedbuilder.gnu.ui.GnuUIPlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Expand Down
2 changes: 1 addition & 1 deletion build/org.eclipse.cdt.managedbuilder.gnu.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2388,7 +2388,7 @@
<targetPlatform
id="cdt.managedbuild.target.gnu.platform.mingw.base"
name="%PlatformName.Dbg"
binaryParser="org.eclipse.cdt.core.PE64"
binaryParser="org.eclipse.cdt.core.GNU_PE64"
Torbjorn-Svensson marked this conversation as resolved.
Show resolved Hide resolved
osList="win32"
archList="all">
</targetPlatform>
Expand Down
2 changes: 1 addition & 1 deletion core/org.eclipse.cdt.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.cdt.core; singleton:=true
Bundle-Version: 8.1.100.qualifier
Bundle-Version: 8.2.0.qualifier
Bundle-Activator: org.eclipse.cdt.core.CCorePlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Expand Down
1 change: 1 addition & 0 deletions core/org.eclipse.cdt.core/plugin.properties
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ ElfParser.name=Elf Parser
GNUElfParser.name=GNU Elf Parser
PEWindowsParser.name=PE Windows Parser (Deprecated)
PE64WindowsParser.name=PE64 Windows Parser
GNUPE64WindowsParser.name=GNU PE64 Windows Parser
CygwinPEParser.name=Cygwin PE Parser (Deprecated)
CygwinPE64Parser.name=Cygwin PE64 Parser
XCOFF32Parser.name=AIX XCOFF32 Parser
Expand Down
10 changes: 10 additions & 0 deletions core/org.eclipse.cdt.core/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@
</run>
</cextension>
</extension>
<extension
id="GNU_PE64"
Torbjorn-Svensson marked this conversation as resolved.
Show resolved Hide resolved
jld01 marked this conversation as resolved.
Show resolved Hide resolved
name="%GNUPE64WindowsParser.name"
point="org.eclipse.cdt.core.BinaryParser">
<cextension>
<run
class="org.eclipse.cdt.utils.coff.parser.GNUPEParser64">
</run>
</cextension>
</extension>
<!-- Deprecated as of CDT 6.9. Use 64 bit version PEParser64 instead.
The class associated with this parser is now the 64-bit handling version. -->
<extension
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*******************************************************************************
* Copyright (c) 2004, 2023 Space Codesign Systems and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Space Codesign Systems - Initial API and implementation
* QNX Software Systems - initial CygwinPEBinaryArchive class
* John Dallaway - Initial GNUPEBinaryArchive64 class (#361)
*******************************************************************************/
package org.eclipse.cdt.utils.coff.parser;

import java.io.IOException;
import java.util.ArrayList;

import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
import org.eclipse.cdt.utils.AR.ARHeader;
import org.eclipse.core.runtime.IPath;

/** @since 8.2 */
public class GNUPEBinaryArchive64 extends PEBinaryArchive64 {

public GNUPEBinaryArchive64(PEParser64 parser, IPath path) throws IOException {
super(parser, path);
}

@Override
protected void addArchiveMembers(ARHeader[] headers, ArrayList<IBinaryObject> children2) {
for (int i = 0; i < headers.length; i++) {
IBinaryObject bin = new GNUPEBinaryObject64(getBinaryParser(), getPath(), headers[i]);
children.add(bin);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*******************************************************************************
* Copyright (c) 2004, 2023 Space Codesign Systems and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Space Codesign Systems - Initial API and implementation
* QNX Software Systems - Initial CygwinPEBinaryExecutable class
* John Dallaway - Initial GNUPEBinaryExecutable64 class (#361)
*******************************************************************************/
package org.eclipse.cdt.utils.coff.parser;

import org.eclipse.cdt.core.IBinaryParser;
import org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable;
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
import org.eclipse.core.runtime.IPath;

/** @since 8.2 */
public class GNUPEBinaryExecutable64 extends GNUPEBinaryObject64 implements IBinaryExecutable {

public GNUPEBinaryExecutable64(IBinaryParser parser, IPath path, int executable) {
super(parser, path, IBinaryFile.EXECUTABLE);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*******************************************************************************
* Copyright (c) 2000, 2023 Space Codesign Systems and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Space Codesign Systems - Initial API and implementation
* QNX Software Systems - Initial CygwinPEBinaryObject class
* John Dallaway - Initial GNUPEBinaryObject64 class (#361)
*******************************************************************************/
package org.eclipse.cdt.utils.coff.parser;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

import org.eclipse.cdt.core.IBinaryParser;
import org.eclipse.cdt.utils.AR.ARHeader;
import org.eclipse.cdt.utils.IGnuToolFactory;
import org.eclipse.cdt.utils.Objdump;
import org.eclipse.core.runtime.IPath;

/** @since 8.2 */
public class GNUPEBinaryObject64 extends PEBinaryObject64 {

public GNUPEBinaryObject64(IBinaryParser parser, IPath path, ARHeader header) {
super(parser, path, header);
}

public GNUPEBinaryObject64(IBinaryParser parser, IPath path, int type) {
super(parser, path, type);
}

@Override
public InputStream getContents() throws IOException {
Torbjorn-Svensson marked this conversation as resolved.
Show resolved Hide resolved
InputStream stream = null;
Objdump objdump = getObjdump();
if (objdump != null) {
try {
byte[] contents = objdump.getOutput();
stream = new ByteArrayInputStream(contents);
} catch (IOException e) {
// Nothing
}
}
if (stream == null) {
stream = super.getContents();
}
return stream;
}

protected Objdump getObjdump() {
IGnuToolFactory factory = getBinaryParser().getAdapter(IGnuToolFactory.class);
if (factory != null) {
return factory.getObjdump(getPath());
}
return null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*******************************************************************************
* Copyright (c) 2004, 2023 Space Codesign Systems and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Space Codesign Systems - Initial API and implementation
* QNX Software Systems - Initial CygwinPEBinaryShared class
* John Dallaway - Initial GNUPEBinaryShared64 class (#361)
*******************************************************************************/
package org.eclipse.cdt.utils.coff.parser;

import org.eclipse.cdt.core.IBinaryParser;
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
import org.eclipse.cdt.core.IBinaryParser.IBinaryShared;
import org.eclipse.core.runtime.IPath;

/** @since 8.2 */
public class GNUPEBinaryShared64 extends GNUPEBinaryObject64 implements IBinaryShared {

protected GNUPEBinaryShared64(IBinaryParser parser, IPath path) {
super(parser, path, IBinaryFile.SHARED);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*******************************************************************************
* Copyright (c) 2000, 2023 Space Codesign Systems and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Space Codesign Systems - Initial API and implementation
* QNX Software Systems - Initial CygwinPEParser class
* John Dallaway - Initial GNUPEParser64 class (#361)
*******************************************************************************/
package org.eclipse.cdt.utils.coff.parser;

import java.io.IOException;

import org.eclipse.cdt.utils.DefaultGnuToolFactory;
import org.eclipse.cdt.utils.IGnuToolFactory;
import org.eclipse.core.runtime.IPath;

/** @since 8.2 */
public class GNUPEParser64 extends PEParser64 {

private IGnuToolFactory toolFactory;

@Override
public String getFormat() {
return "GNU PE"; //$NON-NLS-1$
}

@Override
protected IBinaryArchive createBinaryArchive(IPath path) throws IOException {
return new GNUPEBinaryArchive64(this, path);
}

@Override
protected IBinaryExecutable createBinaryExecutable(IPath path) {
return new GNUPEBinaryExecutable64(this, path, IBinaryFile.EXECUTABLE);
}

@Override
protected IBinaryObject createBinaryCore(IPath path) {
return new GNUPEBinaryObject64(this, path, IBinaryFile.CORE);
}

@Override
protected IBinaryObject createBinaryObject(IPath path) {
return new GNUPEBinaryObject64(this, path, IBinaryFile.OBJECT);
}

@Override
protected IBinaryShared createBinaryShared(IPath path) {
return new GNUPEBinaryShared64(this, path);
}

protected IGnuToolFactory createToolFactory() {
return new DefaultGnuToolFactory(this);
}

@Override
public <T> T getAdapter(Class<T> adapter) {
if (adapter.isAssignableFrom(IGnuToolFactory.class)) {
if (toolFactory == null) {
toolFactory = createToolFactory();
}
return adapter.cast(toolFactory);
}
return super.getAdapter(adapter);
}
}