private long encodeRelative(Address addr, boolean addrIsNormalized, int indexOperation) {
		AddressSpace addressSpace = addr.getAddressSpace();
		int type = addressSpace.getType();
		switch (type) {
			case AddressSpace.TYPE_UNKNOWN:
				if (addr.isHashAddress()) {
					// 60-bit hash address
					return HASH_ADDR_TYPE_LONG | addr.getOffset();
				}
			case AddressSpace.TYPE_RAM:
			case AddressSpace.TYPE_CODE:
			case AddressSpace.TYPE_DELETED:
			case AddressSpace.TYPE_OTHER:
				boolean normalize = !addrIsNormalized && isInDefaultAddressSpace(addr);
				int baseIndex = getBaseAddressIndex(addr, normalize, indexOperation);
				long offset;
				if (baseIndex < 0) {
					if (baseIndex == Integer.MIN_VALUE) {
						// base address not found
						return INVALID_ADDRESS_KEY;
					}
					baseIndex = -baseIndex - 1;
					if (indexOperation == INDEX_MATCH_OR_PREVIOUS) {
						// last address of previous base segment
						offset = MAX_OFFSET;
					}
					else if (indexOperation == INDEX_MATCH_OR_NEXT) {
						// first address of next base segment
						offset = 0;
					}
					else {
						throw new AssertException("unexpected negative base index");
					}
				}
				else {
					offset = normalize ? getNormalizedOffset(addr) : addr.getOffset();
				}
				return RELOCATABLE_ADDR_TYPE_LONG | ((long) baseIndex << ADDR_OFFSET_SIZE) |
					(offset & ADDR_OFFSET_MASK);
			default:
				return encodeAbsolute(addr, indexOperation);
		}
	}
Stack space changed from a common 32-bit space to a compiler-specific
stack space.  This makes bad stack addresses which previously existed
impossible to decode.  Instead of return NO_ADDRESS, we will simply truncate such 
bad stack offsets to the MIN or MAX offsets.
@param offset stack offset
@param stackSpace stack memory space
@return truncated stack offset
Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/map/AddressMapDB.java