Hello everyone,
@Lin thank you for your feedback. However, I don't want to add a constraint on rewriting switch cases in if/else, I would be happy that the compiler can handle it at its end. For instance, GCC is able to remove jump tables even when there are switch cases in the source code with the option "-fno-jump-tables".
@Keith, the example I took was the simple Go code below, so no cgo involved. I built it with the command
go build -gcflags='-N -l' . . I analyzed the binary in Ghidra and I saw the switch tables I mentioned (being actually jump tables) in the .rodata section.
--> However, I figured out that by using the command
go build -o <bin-name> -compiler=gccgo -gccgoflags='-fno-jump-tables' . , I successfully get a binary of the same code without jump tables in the .rodata section. The issue with GCCGO is that it doesn't handle Go functionalities about Go1.18 (see
https://www.mail-archive.com/debian-b...@lists.debian.org/msg1983336.html) so it's quite limiting.
----------------------------------------------
package main
import "fmt"
func main() {
x := 10
switch x {
case 1:
fmt.Println("One")
case 5:
fmt.Println("Five")
case 10:
fmt.Println("Ten")
default:
fmt.Println("Other")
}
}----------------------------------------------
@Ian, I'm working on bug detection, and there seems to be more granularity and therefore more accuracy in analyzing low-level code than source code.
Best,
Karolina