Hello Keith, Thank you for your curiosity.
This is the procedure I follow : 1. I have written the test program main.go below in the directory switch-go 2. I use the command *GOARCH=amd64 GOOS=linux go build -gcflags=all='-N -l' . *with "go version go1.23.3 linux/amd64". 3. I open the produced binary switch-go in the emulator tool of Ghidra, selecting the Golang compiler and launching the default analysis. 4. In the Symbol Tree, I search for "switch" key world, and I find switch tables in the .rodata section, which are actually the jump tables I don't want to have. Following the same procedure with go1.23.3 linux/amd64 and GCCGO 14.2.0 (Ubuntu 14.2.0-4ubuntu2~24.04) , but with the command *GOARCH=amd64 GOOS=linux go build -buildvcs=false -compiler=gccgo -gccgoflags='-fno-jump-tables' . *, I don't have any switch tables (more precisely, jump tables) in the .rodata section (where there are supposed to be if they exist). But again, GCCGO currently doesn't support functionalities for Go above 1.18. Best, Karolina PS : I know I don't need to specify *GOARCH=amd64 GOOS=linux *in the command but I have included them for the purpose of this debugging discussion. *switch-go/main.go*---------------------------------------------- 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") } } ---------------------------------------------- On Saturday, November 30, 2024 at 2:16:20 AM UTC+1 Keith Randall wrote: > Hmm, that's strange. I am not seeing that behavior. > Could you paste the *exact* commands you used to build your program here? > Include GOARCH, GOOS, Go version, and anything else relevant. > How are you determining that there are are still jump tables? Please post > the exact commands you used to determine that also. > > One thing to try is to use "-gcflags=all=-N -l" instead of just > "-gcflags=-N -l". > > > On Friday, November 29, 2024 at 2:58:01 AM UTC-8 Karolina GORNA wrote: > > 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 > <https://www.mail-archive.com/debian-bugs-dist@lists.debian.org/msg1983336.html>) > > so it's quite limiting. > ---------------------------------------------- > > > > > > > > > > > > > > > > > *package mainimport "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 > On Friday, November 29, 2024 at 6:39:02 AM UTC+1 Ian Lance Taylor wrote: > > On Thu, Nov 28, 2024, 1:13 AM 'Karolina GORNA' via golang-nuts < > golan...@googlegroups.com> wrote: > > > @Ian, ok I understand thank you. I am working on Go binary analysis and > this feature would help a lot. > > > Out of curiosity, why do you want to do binary analysis on a program if > you can ask for specific options to be used when building? Why not just do > source analysis, for which there are a bunch of good tools available? > > Ian > > > ------------------------------ > Les informations contenues dans ce message électronique ainsi que celles > contenues dans les documents attachés sont strictement confidentielles et > sont destinées à l'usage exclusif du (des) destinataire(s) nommé(s). > Toute divulgation, distribution ou reproduction, même partielle, en est > strictement interdite sauf autorisation écrite et expresse de l’émetteur. > Si vous recevez ce message par erreur, veuillez le notifier immédiatement > à son émetteur par retour, et le détruire ainsi que tous les documents qui > y sont attachés. > > The information contained in this email and in any document enclosed is > strictly confidential and is intended solely for the use of the individual > or entity to which it is addressed. > Partial or total disclosure, distribution or reproduction of its contents > is strictly prohibited unless expressly approved in writing by the sender. > If you have received this communication in error, please notify us > immediately by responding to this email, and then delete the message and > its attached files from your system. > ------------------------------ > > -- Les informations contenues dans ce message électronique ainsi que celles contenues dans les documents attachés sont strictement confidentielles et sont destinées à l'usage exclusif du (des) destinataire(s) nommé(s). Toute divulgation, distribution ou reproduction, même partielle, en est strictement interdite sauf autorisation écrite et expresse de l’émetteur. Si vous recevez ce message par erreur, veuillez le notifier immédiatement à son émetteur par retour, et le détruire ainsi que tous les documents qui y sont attachés. The information contained in this email and in any document enclosed is strictly confidential and is intended solely for the use of the individual or entity to which it is addressed. Partial or total disclosure, distribution or reproduction of its contents is strictly prohibited unless expressly approved in writing by the sender. If you have received this communication in error, please notify us immediately by responding to this email, and then delete the message and its attached files from your system. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/5cc84075-1717-4a35-9ad2-f43905417745n%40googlegroups.com.