cmd/cgo, windows: llvm-mingw 21 broke something

194 views
Skip to first unread message

Alex

unread,
Aug 31, 2025, 4:15:39 AM (5 days ago) Aug 31
to golang-nuts
Been trying to use go with clang21 on windows but compiling any cgo app results in "cannot parse *.o as ELF, Mach-O, PE or XCOFF"

Tried with go1.24.* and 1.25, using clang20 works as expected.

Michael Oguidan

unread,
Aug 31, 2025, 7:51:08 AM (5 days ago) Aug 31
to golang-nuts
Hi Alex, which version of Go are you using, and why don't use the actual Go compiler which is written in Go.

Alex

unread,
Aug 31, 2025, 7:56:13 AM (5 days ago) Aug 31
to golang-nuts
I am using the go compiler, this is about using cgo together with the go compiler.
And this was with the 1.24 and 1.25 toolchains 

Jason E. Aten

unread,
Aug 31, 2025, 2:23:47 PM (5 days ago) Aug 31
to golang-nuts
Hi Alex,

I haven't worked with Go on Windows in a year, so my knowledge
might be out of date... That said, I found CGO very sensitive to
the exact C compiler used, and even within GCC, the exact version.
Here is the version that I had working at one point in the last couple of years:

mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0 (somewhere on sourceforge I think).

Mind you, I'm not saying you cannot get Clang to work. I'm just suggesting
that if you start with a positive control (that does let you build), then you
can confidently try other compilers knowing that everything else is held the same.

Or you might have gotten what you need with the mingw-w64 gcc, and that's
good enough.  

Let me know if you are able to make Clang work--it would be an interesting data point.

Best,
Jason

Jason E. Aten

unread,
Aug 31, 2025, 2:25:51 PM (5 days ago) Aug 31
to golang-nuts
ah, I see you said "using clang20 works as expected", so I guess clang is working fine
on that version...

Alex

unread,
Aug 31, 2025, 8:26:12 PM (5 days ago) Aug 31
to golang-nuts
Well I have been using bleeding edge clang for a couple of years now, this is the first stable release version to break.
llvm-mingw is even the compiler the builders use so it's the opposite actually, it would be surprising for clang to not work.
See linked issue for reasons why the move to clang:
https://github.com/golang/go/issues/35006#issuecomment-1122405895

Jason E. Aten

unread,
Aug 31, 2025, 9:05:23 PM (5 days ago) Aug 31
to golang-nuts
Since you have the perfect working (clang v20) vs non-working (clang v21)
situation, you could try using 

go build -x -work to see what .o files are being produced

and then

llvm-objdump -f your_object_file.o 

on all of the .o files to see if the types changed?

...and then try to contrast the two: see exactly which file has a "changed" format, if
any -- if you found one that changed, you could go deeper into exactly
what changed; the semantic equivalent of a binary "diff" but based on llvm-objdump

Alex

unread,
Aug 31, 2025, 9:17:49 PM (5 days ago) Aug 31
to golang-nuts
both of them reports coff 
```
_cgo_.o:        file format coff-x86-64
architecture: x86_64
start address: 0x0000000000000000
```

Ian Lance Taylor

unread,
Aug 31, 2025, 10:03:37 PM (5 days ago) Aug 31
to Alex, golang-nuts
On Sun, Aug 31, 2025 at 6:18 PM Alex <alex....@gmail.com> wrote:
>
> both of them reports coff
> ```
> _cgo_.o: file format coff-x86-64
> architecture: x86_64
> start address: 0x0000000000000000
> ```

The error you are getting from cgo means that pe.Open failed on the
object file generated by clang21. Try running a trivial program like
(untested)

package main

import (
"debug/pe"
"fmt"
"os"
)

func main() {
fmt.Println(pe.Open(os.Args[1]))
}


Presumably it will fail if run with the argument being an object
generated by clang21. The error message may suggest what the problem
is.

Ian

Alex

unread,
Aug 31, 2025, 10:06:47 PM (5 days ago) Aug 31
to golang-nuts
That gives me "<nil> offset 0 is before the start of string table"

Ian Lance Taylor

unread,
Aug 31, 2025, 10:34:21 PM (5 days ago) Aug 31
to Alex, golang-nuts
On Sun, Aug 31, 2025 at 7:07 PM Alex <alex....@gmail.com> wrote:
>
> That gives me "<nil> offset 0 is before the start of string table"

Thanks. That implies that some symbol or section name has a long name
with a string table offset of 0. There are several possibilities here.
Can you send us the actual PE object file? Thanks.

Ian
> --
> 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...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/1c69d907-df43-4e20-a572-9c888581c958n%40googlegroups.com.

Chotepud Teo

unread,
Aug 31, 2025, 10:38:55 PM (5 days ago) Aug 31
to Ian Lance Taylor, golang-nuts
gmail blocks object files, even compressed so would need some ideas on how to get it to you

Alex

unread,
Aug 31, 2025, 11:08:10 PM (5 days ago) Aug 31
to golang-nuts
I have sent them over on slack through a DM to Ian

Ian Lance Taylor

unread,
Sep 1, 2025, 10:51:23 AM (4 days ago) Sep 1
to Chotepud Teo, golang-nuts
On Sun, Aug 31, 2025, 7:38 PM Chotepud Teo <alex....@gmail.com> wrote:
gmail blocks object files, even compressed so would need some ideas on how to get it to you

I suggest that you open an issue at https://go.dev/issue and attach the object file there. 

Ian
Reply all
Reply to author
Forward
0 new messages