The plant would alter the direction of its growth toward the available light. The change in growth of a plant in response to an external stimulus is called tropism. In particular, the response of the direction of a plant's growth toward light is called phototropism. This is because, as you stated, plants need sunlight to produce food via photosynthesis to survive.
The hormone responsible for phototropism is called auxin. It causes cells to elongate and is usually present in the cells on the shadowy side of a plant. So the auxin in the cells not facing the sunlight will cause those cells to elongate and ultimately cause the stem to bend in the direction toward the light. That is how phototropism works.