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

Identical Header Guards Cause Resolve Errors #214

Open
buraksenkus opened this issue Dec 27, 2023 · 2 comments
Open

Identical Header Guards Cause Resolve Errors #214

buraksenkus opened this issue Dec 27, 2023 · 2 comments

Comments

@buraksenkus
Copy link
Contributor

asn1/its/Latitude.h, asn1/pki/Latitude.h and asn1/security/Latitude.h files have identical header guards as _Latitude_H_. This causes compile error when more than one of these files are included directly or transitively and one of the data field is tried to be used.

An example case is shown in below figure. As you can see, Latitude_unavailable enum defined in its/Latitude.h cannot be resolved if it is included after other Latitude.h files. Same situation applies for Longitude.h files as well. But there is no error since I didn't include other ones before that.

image

Reordering includes fixes the usage of *_unavailable enums and there might be no such "direct multi-include" situation in most of the time. But this issue is likely to happen "transitively" when trying to implement some security cases.

Additionally, this issue might exist in other data types which has same names. Unfortunately, I didn't have more time to check but this must be considered as well.

I think, the issue is related to asn1c's header guard creation method. From my point of view, making asn1c to append a random suffix to the end of header guard name should fix the problem.

I'm sorry if this issue might be created under asn1c but since the generated files are committed in this repository, it must also be fixed. Thanks in advance!

@riebl
Copy link
Owner

riebl commented Dec 28, 2023

Hi @buraksenkus,

the clash of include guard names is indeed a problem which should be solved by asn1c ultimately.
We may extend our patching mechanism to "uniquify" the guards, e.g. by appending a hash.
For example, we could take the header's path relative to the project root, hash it, and append the last 12 hex symbols of the hash to each include guard. This should be feasible to realize in CMake and produce unique include guards.

@v0-e
Copy link
Contributor

v0-e commented Jan 16, 2024

asn1c (mouse's fork) supports prefixing through the environment variable ASN1C_PREFIX.
It adds a defined prefix in every C type associated with an ASN.1 definition, including also the header guards.
Can be a possible solution, not only for this issue, but also to eventually support ITS messages of several versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants