-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: -godefs makes negative values from unsigned constants on openbsd/386 #2470
Labels
Comments
Looks like it is #define BIOCGDLTLIST _IOWR('B',123, struct bpf_dltlist) #define _IOWR(g,n,t) _IOC(IOC_INOUT, (g), (n), sizeof(t)) #define _IOC(inout,group,num,len) \ (inout | ((len & IOCPARM_MASK) << 16) | ((group) << 8) | (num)) #define IOC_OUT (unsigned long)0x40000000 #define IOC_IN (unsigned long)0x80000000 #define IOC_INOUT (IOC_IN|IOC_OUT) #define IOCPARM_MASK 0x1fff |
On my Mac, running cgo -godefs on this program produces the correct (unsigned) output: package main /* struct bpf_dltlist { int x[4]; }; #define BIOCGDLTLIST _IOWR('B',123, struct bpf_dltlist) #define _IOWR(g,n,t) _IOC(IOC_INOUT, (g), (n), sizeof(t)) #define _IOC(inout,group,num,len) (inout | ((len & IOCPARM_MASK) << 16) | ((group) << 8) | (num)) #define IOC_OUT (unsigned long)0x40000000 #define IOC_IN (unsigned long)0x80000000 #define IOC_INOUT (IOC_IN|IOC_OUT) #define IOCPARM_MASK 0x1fff */ import "C" const ( BIOCGDLTLIST = C.BIOCGDLTLIST ) Owner changed to @rsc. Status changed to Accepted. |
The problem is that we extract the value of complicated #define values by sticking them in enum { X = theDefine }; and then reading the value out of the debug info. The C spec is super vague about the concrete type of an enum type, but often the compiler picks int, and in this case, on OpenBSD/386, the defined value is negative if interpreted as an int. There are many things we could do but the easiest is probably to stop using the enum values entirely. Cgo already has code to generate a long long array with the values and then read the values out of the object file directly for Mach-O. This was necessary for Apple's latest LLVM-based gcc implementations, which have taken an axe to the amount of useful DWARF information they leave in the object. If we make the ELF systems read that array too, then it might all just work. Want to give it a try, Mikio? |
This issue was closed by revision 4cfcb4a. Status changed to Fixed. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Attachments:
The text was updated successfully, but these errors were encountered: