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

opj_includes.h shouldn't define __attribute__ #727

Closed
nico opened this issue Mar 17, 2016 · 4 comments
Closed

opj_includes.h shouldn't define __attribute__ #727

nico opened this issue Mar 17, 2016 · 4 comments
Milestone

Comments

@nico
Copy link

nico commented Mar 17, 2016

opj_includes.h has this snippet:

/* Ignore GCC attributes if this is not GCC */
#ifndef __GNUC__
    #define __attribute__(x) /* __attribute__(x) */
#endif

That's not valid, things starting with two underscores are reserved for the implementation and shouldn't be redefined. In practice, it's even actively harmful: When building openjpeg with clang-cl, __GNUC__ isn't defined, so __attribute__ gets defined to nothing, and then the same file includes <intrin.h> a bit futher down. clang-cl's intrin.h header uses __attribute__ internally, and since it's included after this redefine, clang-cl gets very confused.

One approach would be to do

#ifndef __GNUC__
  #define ATTRIB(x) __attribute__(x)
#else
  #define ATTRIB(x)
#endif

And then use ATTRIB everywhere -- but from what I can tell, all uses of __attribute__ are already guarded by other diffs and just deleting these 4 lines should probably be fine too.

(This blocks https://crbug.com/592745)

@stweil
Copy link
Contributor

stweil commented Mar 17, 2016

At least Debian's clang also defines __GNUC__, so I assume that normally there is no problem. clang-cl tries to be compatible to Microsoft's compiler cl which of course does not define __GNUC__. Maybe for this special case #if defined(__GNUC__) || defined(__clang__) would be better.

@nico
Copy link
Author

nico commented Mar 17, 2016

Well, clang defines __GNUC__ when it's in gcc mode. In clang-cl mode, when it emulates cl.exe and not gcc, it doesn't but defines _MSC_VER instead.

For this case, not defining something starting with __ is best, as that's not allowed per standard :-)

(I work on clang.)

@nico
Copy link
Author

nico commented Mar 18, 2016

FWIW, I just removed these 4 lines in the version of openjpeg used in pdfium (the library Chromium uses to render pdf files), and at least on the platforms we build on everything kept working. So maybe just deleting these 4 lines is an option. (https://codereview.chromium.org/1810373002/diff/20001/third_party/libopenjpeg20/opj_includes.h)

@nico
Copy link
Author

nico commented Apr 24, 2016

Thanks! :-)

@mayeut mayeut added this to the OPJ v2.1.1 milestone Apr 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants