Closed Bug 923486 Opened 11 years ago Closed 11 years ago

In ASAN builds, NS_IsMainThread is declared "static" in a header

Categories

(Core :: XPCOM, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla27

People

(Reporter: mccr8, Assigned: mccr8)

References

(Blocks 2 open bugs)

Details

Attachments

(2 files, 2 obsolete files)

I'm seeing a bunch of these warnings in an ASAN build:

10:08.55 ../../dist/include/MainThreadUtils.h:36:6: warning: 'static' function 'NS_IsMainThread' declared in header file should be declared 'static inline' [-Wunneeded-internal-declaration]

10:05.05 ../../dist/include/MainThreadUtils.h:36:6: warning: unused function 'NS_IsMainThread' [-Wunused-function]

NS_IsMainThread is declared like this:

#ifdef MOZ_ASAN
// Temporary workaround, see bug 895845
MOZ_ASAN_BLACKLIST static
#else
inline
#endif
bool NS_IsMainThread()
{
  return gTLSThreadID == mozilla::threads::Main;
}

It looks like the fix is just to drop the "static".  Decoder, I assume that won't break this ASAN workaround you implemented?
Flags: needinfo?(choller)
Assignee: nobody → continuation
Blocks: buildwarning
Attached patch de-static (obsolete) — Splinter Review
Well, that doesn't work, as it results in a bunch of linker errors like this:

14:52.97 /usr/bin/ld.gold: error: /home/amccreight/ff-dbg-asan/toolkit/library/../components/places/SQLFunctions.o: multiple definition of 'NS_IsMainThread()'
14:52.97 /usr/bin/ld.gold: /home/amccreight/ff-dbg-asan/toolkit/library/../xre/ProfileReset.o: previous definition here
Flags: needinfo?(choller)
Shouldn't you be marking the function as inline?
Well, what the original patch was trying to fix is that the build hits a Clang bug if IsMainThread is inlined.  MOZ_ASAN_BLACKLIST says something shouldn't be inlined.  I'm trying a new patch now that doesn't inline define NS_IsMainThread for ASAN builds, which is more consistent...
Attached patch uninline, now with building (obsolete) — Splinter Review
Attachment #813576 - Attachment is obsolete: true
I don't know if the static is required, I just know that the function must not be inlined, otherwise the blacklisting doesn't work. The original fix (including the static) was suggested by kcc (Google/ASan dev) to fix our intermittent crash until the bug is fixed on the Clang/ASan side. If you can remove the static without breaking the blacklisting, then I'm fine with that :)
Comment on attachment 813599 [details] [diff] [review]
uninline, now with building

This works locally for me in an ASAN build, but I don't think I have the version that had the problem.  Could you please check this patch, decoder, to make sure it doesn't break things for you?
Attachment #813599 - Flags: feedback?(choller)
Comment on attachment 813599 [details] [diff] [review]
uninline, now with building

Green on try, what could possibly go wrong :)

https://tbpl.mozilla.org/?tree=Try&rev=4d47bc8e6c6c
Attachment #813599 - Flags: feedback?(choller) → feedback+
Attachment #813599 - Flags: review?(ehsan)
Comment on attachment 813599 [details] [diff] [review]
uninline, now with building

Review of attachment 813599 [details] [diff] [review]:
-----------------------------------------------------------------

::: xpcom/glue/nsThreadUtils.cpp
@@ +136,5 @@
>    bool result = false;
>    nsThreadManager::get()->nsThreadManager::GetIsMainThread(&result);
>    return bool(result);
>  }
> +#elif defined(MOZ_ASAN)

Please put this in an independent #ifdef to make the conditions the exact same in both the .h and .cpp files.
Attachment #813599 - Flags: review?(ehsan) → review+
(In reply to :Ehsan Akhgari (needinfo? me!) from comment #9)
> Please put this in an independent #ifdef to make the conditions the exact
> same in both the .h and .cpp files.
The #ifdef conditions are already pretty divergent.  I'll write a separate patch to harmonize the existing state of affairs and then update my patch on top of that.

Currently, it looks like:
CPP file:
#ifndef MOZILLA_INTERNAL_API
  CASE-1
#elif defined(XP_WIN)
  CASE-2
#elif !defined(NS_TLS)
  CASE-3
#endif // nothing for CASE-4

H file:
#if defined(MOZILLA_INTERNAL_API) && defined(XP_WIN)
  CASE-2
#elif defined(MOZILLA_INTERNAL_API) && defined(NS_TLS)
  CASE-4
#else
  CASE-1 + CASE-3
#endif
Carrying forward Ehsan's r+.

debug try run: https://tbpl.mozilla.org/?tree=Try&rev=6bb0b6f88eeb

I need to reverify that this new version builds in ASAN.
Attachment #813599 - Attachment is obsolete: true
Attachment #818516 - Flags: review+
Thank you for doing this!
Attachment #818515 - Flags: review?(ehsan)
Attachment #818515 - Flags: review?(ehsan) → review+
https://hg.mozilla.org/mozilla-central/rev/8c34a47385fd
https://hg.mozilla.org/mozilla-central/rev/d57a11856d8b
Status: NEW → RESOLVED
Closed: 11 years ago
Flags: in-testsuite-
Resolution: --- → FIXED
Target Milestone: --- → mozilla27
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: