Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-6667 don't lock-in empty func sigs for rust+dwarf

dev747368d3c69ea31923
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/DWARFFunction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/DWARFFunction.java
index da55530e66..1ef7d31b2f 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/DWARFFunction.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/DWARFFunction.java
@@ -40,7 +40,7 @@ import ghidra.util.exception.*;
* Represents a function that was read from DWARF information.
*/
public class DWARFFunction {
- public enum CommitMode { SKIP, FORMAL, STORAGE, }
+ public enum CommitMode { SKIP, FORMAL, STORAGE, NO_PARAMS }
public DIEAggregate diea;
public DWARFName name;
@@ -456,27 +456,33 @@ public class DWARFFunction {
public void updateFunctionSignature() {
try {
- boolean includeStorageDetail = signatureCommitMode == CommitMode.STORAGE;
- FunctionUpdateType functionUpdateType = includeStorageDetail
- ? FunctionUpdateType.CUSTOM_STORAGE
- : FunctionUpdateType.DYNAMIC_STORAGE_ALL_PARAMS;
-
- Parameter returnVar = retval.asReturnParameter(includeStorageDetail);
- List<Parameter> parameters = getParameters(includeStorageDetail);
-
- if (includeStorageDetail && !retval.isZeroByte() && retval.isMissingStorage()) {
- // TODO: this logic is faulty and borks the auto _return_storage_ptr_ when present
- // Update return value in a separate step as its storage isn't typically specified
- // in dwarf info.
- // This will allow automagical storage assignment for return value by ghidra.
- function.updateFunction(callingConventionName, returnVar, List.of(),
- FunctionUpdateType.DYNAMIC_STORAGE_ALL_PARAMS, true, SourceType.IMPORTED);
- returnVar = null; // don't update it in the second call to updateFunction()
- }
+ if (signatureCommitMode != CommitMode.NO_PARAMS) {
+ boolean includeStorageDetail = signatureCommitMode == CommitMode.STORAGE;
+ FunctionUpdateType functionUpdateType = includeStorageDetail
+ ? FunctionUpdateType.CUSTOM_STORAGE
+ : FunctionUpdateType.DYNAMIC_STORAGE_ALL_PARAMS;
+
+ Parameter returnVar = retval.asReturnParameter(includeStorageDetail);
+ List<Parameter> parameters = getParameters(includeStorageDetail);
+
+ if (includeStorageDetail && !retval.isZeroByte() && retval.isMissingStorage()) {
+ // TODO: this logic is faulty and borks the auto _return_storage_ptr_ when present
+ // Update return value in a separate step as its storage isn't typically specified
+ // in dwarf info.
+ // This will allow automagical storage assignment for return value by ghidra.
+ function.updateFunction(callingConventionName, returnVar, List.of(),
+ FunctionUpdateType.DYNAMIC_STORAGE_ALL_PARAMS, true, SourceType.IMPORTED);
+ returnVar = null; // don't update it in the second call to updateFunction()
+ }
- function.updateFunction(callingConventionName, returnVar, parameters,
- functionUpdateType, true, SourceType.IMPORTED);
- function.setVarArgs(varArg);
+ function.updateFunction(callingConventionName, returnVar, parameters,
+ functionUpdateType, true, SourceType.IMPORTED);
+ function.setVarArgs(varArg);
+ }
+ else {
+ // omit setting SourceType to allow other analyzers to provide param info
+ function.setCallingConvention(callingConventionName);
+ }
function.setNoReturn(noReturn);
}
catch (InvalidInputException | IllegalArgumentException | DuplicateNameException e) {
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/funcfixup/RustDWARFFunctionFixup.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/funcfixup/RustDWARFFunctionFixup.java
index b6ed905bb0..871e766455 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/funcfixup/RustDWARFFunctionFixup.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/funcfixup/RustDWARFFunctionFixup.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -39,7 +39,15 @@ public class RustDWARFFunctionFixup implements DWARFFunctionFixup {
int cuLang = diea.getCompilationUnit().getLanguage();
if (cuLang == DWARFSourceLanguage.DW_LANG_Rust) {
dfunc.callingConventionName = getRustCC(dfunc.getProgram().getGhidraProgram());
- dfunc.signatureCommitMode = CommitMode.FORMAL;
+ if (dfunc.params.isEmpty() && dfunc.diea.getTypeRef() == null) {
+ // if there were no defined parameters and return type specified, don't force
+ // an empty param signature for this function. (Rust can emit these kind of stub
+ // DIEs when compiled without -g)
+ dfunc.signatureCommitMode = CommitMode.NO_PARAMS;
+ }
+ else {
+ dfunc.signatureCommitMode = CommitMode.FORMAL;
+ }
}
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/funcfixup/StorageVerificationDWARFFunctionFixup.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/funcfixup/StorageVerificationDWARFFunctionFixup.java
index 03c61543b8..4c5d6502c7 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/funcfixup/StorageVerificationDWARFFunctionFixup.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/funcfixup/StorageVerificationDWARFFunctionFixup.java
@@ -31,6 +31,10 @@ public class StorageVerificationDWARFFunctionFixup implements DWARFFunctionFixup
@Override
public void fixupDWARFFunction(DWARFFunction dfunc) {
+ if (dfunc.signatureCommitMode == CommitMode.NO_PARAMS) {
+ // storage will already be ignored
+ return;
+ }
DWARFRegisterMappings regMappings = dfunc.getProgram().getRegisterMappings();
boolean ignoreStorage = dfunc.getProgram().getImportOptions().isIgnoreParamStorage() ||
(regMappings != null && regMappings.isUseFormalParameterStorage());