void setThunkedFunction(FunctionDB function, FunctionDB referencedFunction)
			throws IllegalArgumentException {

		if (function.isExternal()) {
			throw new UnsupportedOperationException("External functions may not be a thunk");
		}
		try {
			if (referencedFunction == null) {
				if (!function.isThunk()) {
					return;
				}
				thunkAdapter.removeThunkRecord(function.getKey());
				function.setInvalid();
			}
			else {

				FunctionDB refFunc = (FunctionDB) getFunctionAt(referencedFunction.getEntryPoint());
				if (refFunc != referencedFunction) {
					throw new IllegalArgumentException("thunkedFunction not found within program");
				}
				referencedFunction.checkDeleted();

				Function endFunction = referencedFunction;
				while (endFunction != function && endFunction.isThunk()) {
					endFunction = endFunction.getThunkedFunction(false);
				}
				if (endFunction == function) {
					throw new IllegalArgumentException(
						"Cannot create a thunk function which results in loop to itself");
				}

				Symbol s = function.getSymbol();
				String oldName = s.getName();

				thunkAdapter.createThunkRecord(function.getKey(), referencedFunction.getKey());
				function.setInvalid();

				// Default thunk function name changes dynamically as a result of becoming a thunk
				if (s.getSource() == SourceType.DEFAULT) {
					program.symbolChanged(s, ProgramEvent.SYMBOL_RENAMED, function.getEntryPoint(),
						s, oldName, s.getName());
				}
			}
			program.setChanged(new FunctionChangeRecord(function, THUNK_CHANGED));
		}
		catch (IOException e) {
			dbError(e);
		}
	}
Transform an existing external symbol into an external function.
This method should only be invoked by the Function Manager.
The {@link ExternalLocation#getOriginalImportedName() original imported name} will initially 
be null.

@param extSpaceAddr the external space address to use when creating this external.  Any 
other symbol using this address must first be deleted.  Results are unpredictable if this is 
not done.
@param name the external function name
@param nameSpace the external function namespace
@param externalProgramAddress the external program address (may be null)
@param originalImportName the original imported name if different from name (may be null)
@param source the source of this external.
@return external function
@throws InvalidInputException if the name is invalid
Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/function/FunctionManagerDB.java