Merge remote-tracking branch 'origin/GP-6667_dev747368_rust_dwarf_empty_func_params'

This commit is contained in:
Ryan Kurtz
2026-04-29 07:08:02 -04:00
3 changed files with 40 additions and 22 deletions
@@ -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;
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);
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 (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);
}
else {
// omit setting SourceType to allow other analyzers to provide param info
function.setCallingConvention(callingConventionName);
}
function.updateFunction(callingConventionName, returnVar, parameters,
functionUpdateType, true, SourceType.IMPORTED);
function.setVarArgs(varArg);
function.setNoReturn(noReturn);
}
catch (InvalidInputException | IllegalArgumentException | DuplicateNameException e) {
@@ -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;
}
}
}
@@ -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());