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

Add clang to compiler.h #2397

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add clang to compiler.h #2397

wants to merge 1 commit into from

Conversation

Ryzee119
Copy link
Contributor

@Ryzee119 Ryzee119 commented Jan 6, 2024

Describe the PR
I'm using the clang compiler which for our purposes the compiler attributes match GCC from what I can read.

Although TU_ATTR_WEAK had to be changed to __attribute__ ((weak_import)) or I was getting lld: error: duplicate symbol errors on all the TU_ATTR_WEAK functions.

@@ -175,6 +175,11 @@
#pragma GCC poison tud_vendor_control_request_cb
#endif

#if defined (__clang__)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you do the #ifdef #else instead of undef (ust move this up). undef is rather confusing since people may only look at the first define.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify @hathach

Like this?

#if defined(__GNUC__) || defined (__clang__)
  #define TU_ATTR_ALIGNED(Bytes)        __attribute__ ((aligned(Bytes)))
  #define TU_ATTR_SECTION(sec_name)     __attribute__ ((section(#sec_name)))
  #define TU_ATTR_PACKED                __attribute__ ((packed))
  #if defined(__GNUC__)
    #define TU_ATTR_WEAK                  __attribute__ ((weak))
  #else
    #define TU_ATTR_WEAK                  __attribute__ ((weak_import))
  #endif
... 
...

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, but the otherway around

  #if defined(__clang__)
    #define TU_ATTR_WEAK                  __attribute__ ((weak_import))
  #else
    #define TU_ATTR_WEAK                  __attribute__ ((weak))
  #endif

Copy link
Contributor Author

@Ryzee119 Ryzee119 Jan 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All fixed :)
Not sure why pre-commit CI is failing 🤔

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unit test probably compile using clang, and has affected by this attribute. I will check later.

Copy link
Owner

@hathach hathach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still haven't got time to test this out, will be off for a couple of week for TET holidays. Please be patient, thank you.

@hathach
Copy link
Owner

hathach commented Feb 22, 2024

@Ryzee119 I am back from TET holidays, which compiler you are using. If it is arm clang, I could give it a try (was planning to support it anwyay).

Copy link
Owner

@hathach hathach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recently I switch to use weak as the default implementation of callback to be compatible with keil #2239

https://github.com/hathach/tinyusb/blob/master/src/device/usbd.c#L48

the other callback header can work with weak_import, but this style seems to require actual weak and cause the compile issue with unit-test (since test include mocking of dcd layer).

Maybe I should use weakref/alias or unify them all to default implemenation, will revise later. We probably need to keep this open until then. Thank you.

@HiFiPhile
Copy link
Collaborator

How it goes with #2606 ?

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

Successfully merging this pull request may close these issues.

None yet

3 participants