According to Halacha, during the Torah reading, Jews should not leave the synagogue where the Torah reading is occurring. However, is it permissible for them to leave if they have to use the restroom, or are they expected to wait until the Aliyah is over to go?
One who delays his cavities [from elimination] transgresses the commandment, "You shall not make yourselves loathsome."
R Yaakov Goldstein brings here two relevant answers that help with your question
The above prohibition of Bal Tishaktzu only applies when the person feels a certain amount of pressure to relieve himself. Some opinions define this to mean that if he cannot withhold himself for a Parsa distance (approximately 72 minutes)
He goes on to explain (see there source 30) that one may withhold his needs if he is in middle of a speech or other public performance. This would then be so even more for the reading of the Torah, especially since the time to read an alyia is typically quite short.