Masks and outlines

I’m kind of new to blender, and I created an account here just to ask this:

I want to render an object with a black outline/edge, but I need a mask to cover ir partially. My problem is that the edge affects the object I want to render AND the mask, and I’d like to have the outline only on the main object. Is it possible?

Sorry for my bad english, I made an image to explain better. Picture 1 is the placement of the meshes (gray is the mask, red is the main object), picture 2 is what I want to render, and picture 3 is what I’m getting.

Use nodes in compositor to subtract the mask (square) from the circle, then add an outline possibly from erode/dilate node.