On ARM in thumb mode, it is possible to build a "jump table" (jump to the n-th pointer) as follows:
tbb [pc, r1]
.byte (foofoo1-.Ltable)/2
.byte (foofoo2-.Ltable)/2
This only works if each of the (foofoo1-.Ltable)/2
expressions fits within 0…255. There does not seem to be a safe and simple way to check for this. GNU assembler checks that these bytes fit within -128…255, which is insufficient. clang does not even check.
.byte -((foofoo1-.Ltable)/2)*(foofoo1>.Ltable) + (foofoo1<=.Ltable)*100000
works with GNU assembler for checking that the byte is nonnegative (it produces -100000 if it is negative, which triggers the overflow check), but this does not work with clang.
Is there any way to reliably check for the range of an expression involving differences of labels?
I suppose compilers have their own way to check is a label is within a certain number of bytes from another label, or at least safely approximate this decision, but I'd like a double check on this.