Gimbal lock is a problem for euler angle representation of rotations, not rotation matrices themselves. You can fix it for euler angles the same way they used to for old mechanical gimbal gyroscopes. By having a fourth rotation of the frame that points the singularity out of the way. This is a typical solution in navigation for dealing with the poles of the earth (a wander angle frame).