Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/cgo: gcc attribute unavailable breaks cgo #2888

gopherbot opened this issue Feb 6, 2012 · 3 comments


Copy link

commented Feb 6, 2012


If a C header contains a function declaration such as
    extern const char *class_getName(Class cls);
where Class is the typedef name for struct objc_class * then the C wrapper code
generated by cgo uses type struct objc_class * for unmarshalling the function argument
rather than type Class.  Normally this is fine but in this case the definition of struct
objc_class has the 'unavailable' attribute attached to it, so the generated code fails
to compile.

What steps will reproduce the problem?
1. Unzip/untar attached cgo_example.tar.gz and cd to cgo_example.
2. cgo main.go
3. gcc -c -I. _obj/main.cgo2.c

What is the expected output?
No output - compilation succeeds silently.

What do you see instead?
main.go: In function ‘_cgo_451c23f32582_Cfunc_class_getName’:
main.go:30: error: ‘objc_class’ is unavailable (declared at ./c_header.h:1)

Which compiler are you using (5g, 6g, 8g, gccgo)?

Which operating system are you using?
Mac OS X 10.7.3

Which revision are you using?  (hg identify)
weekly.2012-01-27 11507

Please provide any additional information below.
I produced a modified version of cgo by deleting the *dwarf.TypedefType switch case in
func (c *typeConv) FuncArg() at approx line 1275 in src/cmd/cgo/gcc.go .  This had the
effect of using the argument type as given in the C header and allowed compilation of
the generated wrapper code to succeed.


  1. cgo_example.tar.gz (445 bytes)

This comment has been minimized.

Copy link

commented Feb 14, 2012

Comment 1:

Typedefs are just not a good match for Go.  But if we remove the processing of typedefs,
things typically get worse, since C.FILE stops working.

Labels changed: added priority-go1, removed priority-triage.

Owner changed to

Status changed to Accepted.


This comment has been minimized.

Copy link

commented Feb 17, 2012

Comment 2:

Single-file test:
package main
typedef struct objc_class *Class;
struct objc_class {
    Class isa;
} __attribute__((unavailable));
extern __attribute__((visibility("default")))
    const char *class_getName(Class cls)
const char *class_getName(Class cls) { return "foo"; }
import "C"
import "fmt"
func main() {
    class := C.Class(nil)
Attribute unavailable seems like a terrible idea, but I think we can work around it by
using typedef names when possible in the generated C code.

Status changed to Started.


This comment has been minimized.

Copy link

commented Feb 19, 2012

Comment 3:

This issue was closed by revision 1a0c8fe.

Status changed to Fixed.

@rsc rsc added this to the Go1 milestone Apr 10, 2015

@rsc rsc removed the priority-go1 label Apr 10, 2015

@golang golang locked and limited conversation to collaborators Jun 24, 2016

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
2 participants
You can’t perform that action at this time.