Comments (5)
GO has a special parser implementation, it takes the functions and adds custom labels https://github.com/compiler-explorer/compiler-explorer/blob/main/lib/compilers/golang.ts#L152 - starting with _pc0
I think based on that information, we can make a custom implementation for CFG
from compiler-explorer.
Thanks for reporting this!
Compiler-explorer uses some heuristics to parse the assembly output, among others - to partition it into functions. Unfortunately these heuristics fail for the go compiler gc
, and what's worse - I myself cannot distinguish basic-blocks from functions in its output format :( So not sure this is solvable.
(Ideas are very welcome - eg is anyone aware of gc
flags that somehow control formatting of assembly output?)
gccgo
does produce parsable assembly output (block labels start with a dot), and cfg generation indeed succeeds: https://godbolt.org/z/M9YaY1oT9
Perhaps this is a valid workaround?
from compiler-explorer.
Looking at the full asm dump of the default go program https://godbolt.org/z/zx1EvK8zd :
.file 1 "<source>"
.loc 1 5 0
TEXT main.Square(SB), NOSPLIT|NOFRAME|ABIInternal, $0-8
FUNCDATA $0, gclocals·g2BeySu+wFnoycgXfElmcg==(SB)
FUNCDATA $1, gclocals·g2BeySu+wFnoycgXfElmcg==(SB)
FUNCDATA $5, main.Square.arginfo1(SB)
FUNCDATA $6, main.Square.argliveinfo(SB)
PCDATA $3, $1
.loc 1 6 0
IMULQ AX, AX
RET
.loc 1 9 0
TEXT main.main(SB), NOSPLIT|NOFRAME|ABIInternal, $0-0
FUNCDATA $0, gclocals·g2BeySu+wFnoycgXfElmcg==(SB)
FUNCDATA $1, gclocals·g2BeySu+wFnoycgXfElmcg==(SB)
RET
It seems there's little hope of parsing this dump programmatically - this one doesn't even contain labels for function name, let alone basic blocks.
from compiler-explorer.
Hey, sorry for the slow response and thanks for taking a look.
I was wondering how exactly godbolt runs the Go compiler to obtain the dump you showed without function names?
I tried using Go 1.22.1 by setting the GOTOOLCHAIN
environment variable, meaning using the standard Go-managed build of Go 1.22.1.
The UI shows it’s using the following compiler flags:
But when I compile the square code like that, I get:
GOTOOLCHAIN=go1.22.1 go build -o output.s -gcflags=-S default.go
# command-line-arguments
main.Square STEXT nosplit size=5 args=0x8 locals=0x0 funcid=0x0 align=0x0
0x0000 00000 (/tmp/ce/default.go:5) TEXT main.Square(SB), NOSPLIT|NOFRAME|ABIInternal, $0-8
0x0000 00000 (/tmp/ce/default.go:5) FUNCDATA $0, gclocals·g2BeySu+wFnoycgXfElmcg==(SB)
0x0000 00000 (/tmp/ce/default.go:5) FUNCDATA $1, gclocals·g2BeySu+wFnoycgXfElmcg==(SB)
0x0000 00000 (/tmp/ce/default.go:5) FUNCDATA $5, main.Square.arginfo1(SB)
0x0000 00000 (/tmp/ce/default.go:5) FUNCDATA $6, main.Square.argliveinfo(SB)
0x0000 00000 (/tmp/ce/default.go:5) PCDATA $3, $1
0x0000 00000 (/tmp/ce/default.go:6) IMULQ AX, AX
0x0004 00004 (/tmp/ce/default.go:6) RET
0x0000 48 0f af c0 c3 H....
main.main STEXT nosplit size=1 args=0x0 locals=0x0 funcid=0x0 align=0x0
0x0000 00000 (/tmp/ce/default.go:9) TEXT main.main(SB), NOSPLIT|NOFRAME|ABIInternal, $0-0
0x0000 00000 (/tmp/ce/default.go:9) FUNCDATA $0, gclocals·g2BeySu+wFnoycgXfElmcg==(SB)
0x0000 00000 (/tmp/ce/default.go:9) FUNCDATA $1, gclocals·g2BeySu+wFnoycgXfElmcg==(SB)
0x0000 00000 (/tmp/ce/default.go:9) RET
0x0000 c3 .
go:cuinfo.producer.main SDWARFCUINFO dupok size=0
0x0000 72 65 67 61 62 69 regabi
go:cuinfo.packagename.main SDWARFCUINFO dupok size=0
0x0000 6d 61 69 6e main
main..inittask SNOPTRDATA size=8
0x0000 00 00 00 00 00 00 00 00 ........
gclocals·g2BeySu+wFnoycgXfElmcg== SRODATA dupok size=8
0x0000 01 00 00 00 00 00 00 00 ........
main.Square.arginfo1 SRODATA static dupok size=3
0x0000 00 08 ff ...
main.Square.argliveinfo SRODATA static dupok size=2
0x0000 00 00 ..
So I’m wondering if the function names get lost somewhere else or if I’m reproducing it wrong.
Regarding the basic blocks, what would we need to change in Go to make that work? Just emit more labels in the assembly output?
Thanks
from compiler-explorer.
@partouf is right of course, I missed the custom parser.
from compiler-explorer.
Related Issues (20)
- ppc64 and ppc64le nightly cross gcc failures HOT 1
- [REQUEST]: Permit "Add Executor" to Conformance View
- [BUG]: Xtensa ESP32 LEND loop targets are filtered as directives HOT 4
- [COMPILER REQUEST]: GraalVM Native Image
- [BUG]: code compiles to either infinite loop or nothing with -O3 HOT 3
- [COMPILER REQUEST]: QuickJS
- TypeError: opcodes is not iterable
- Can't link with gcc 4.7.1 and 4.7.2 HOT 1
- [BUG]: recompiling resets scroll position to the top
- [LIB REQUEST] pycryptodome & cryptography
- [COMPILER REQUEST]: sh-elf-gdc HOT 4
- [BUG]: Mobile mode can't be edited? HOT 1
- [BUG]: Browser tab refresh resets all renamed CE tabs
- [COMPILER REQUEST]: Groovy HOT 1
- [BUG]: char8_t not declared even with -std=c23 HOT 1
- Make lines linkable HOT 3
- [BUG]: preprocessor output is empty when using MS compiler
- [BUG]: permission denied opening /dev/null HOT 5
- [BUG]: Mfem library not loading: single vs double precision not specified
- [BUG]: Internal Compiler Explorer error: Error: Unexpected basic block terminator: HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from compiler-explorer.