Make NS_IMETHOD set hidden symbol visibility by default on ELF platforms. This is always desirable for virtual methods implemented in XPCOM component libraries, since it's impossible to reference the symbol from outside of the library. The behavior can be overridden as needed, such as a base class in a shared library that's linked against. For more details, see the comments in nscore.h and bug 227537. r=dbaron, sr=darin.

git-svn-id: svn://10.0.0.236/trunk@152211 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
bryner%brianryner.com 2004-02-03 08:32:33 +00:00
parent ac3bc59264
commit 34c56dea27
19 changed files with 172 additions and 21 deletions

View File

@ -1903,6 +1903,43 @@ if test "$ac_cv_have_mbrtowc" = "yes"; then
fi
AC_LANG_C
dnl Check for .hidden assembler directive and visibility attribute.
dnl Borrowed from glibc configure.in
dnl ===============================================================
if test "$GNU_CC"; then
AC_CACHE_CHECK(for .hidden assembler directive,
ac_cv_asm_hidden_directive, [dnl
cat > conftest.s <<EOF
.hidden foo
foo:
EOF
if AC_TRY_COMMAND(${CC-cc} -c $CFLAGS conftest.s 1>&5); then
ac_cv_asm_hidden_directive=yes
else
ac_cv_asm_hidden_directive=no
fi
rm -f conftest*])
if test $ac_cv_asm_hidden_directive = yes; then
AC_CACHE_CHECK(whether __attribute__((visibility())) is supported,
ac_cv_visibility_attribute,
[cat > conftest.c <<EOF
int foo __attribute__ ((visibility ("hidden"))) = 1;
EOF
ac_cv_visibility_attribute=no
if ${CC-cc} -Werror -S conftest.c -o conftest.s >/dev/null 2>&1; then
if grep '\.hidden.*foo' conftest.s >/dev/null; then
ac_cv_visibility_attribute=yes
fi
fi
rm -f conftest.[cs]
])
if test $ac_cv_visibility_attribute = yes; then
AC_DEFINE(HAVE_VISIBILITY_ATTRIBUTE)
fi
fi # have hidden directive
fi # GNU_CC
dnl Checks for header files.
dnl ========================================================
AC_HEADER_DIRENT

View File

@ -59,10 +59,10 @@ public:
nsFontCache();
virtual ~nsFontCache();
NS_IMETHOD Init(nsIDeviceContext* aContext);
NS_IMETHOD GetDeviceContext(nsIDeviceContext *&aContext) const;
NS_IMETHOD GetMetricsFor(const nsFont& aFont, nsIAtom* aLangGroup,
nsIFontMetrics *&aMetrics);
virtual nsresult Init(nsIDeviceContext* aContext);
virtual nsresult GetDeviceContext(nsIDeviceContext *&aContext) const;
virtual nsresult GetMetricsFor(const nsFont& aFont, nsIAtom* aLangGroup,
nsIFontMetrics *&aMetrics);
nsresult FontMetricsDeleted(const nsIFontMetrics* aFontMetrics);
nsresult Compact();
@ -70,8 +70,8 @@ public:
/* printer device context classes may create their own
* subclasses of nsFontCache (and override this method) and override
* DeviceContextImpl::CreateFontCache (see bug 81311).
*/
NS_IMETHOD CreateFontMetricsInstance(nsIFontMetrics** fm);
*/
virtual nsresult CreateFontMetricsInstance(nsIFontMetrics** fm);
protected:
nsVoidArray mFontMetrics;
@ -79,6 +79,9 @@ protected:
// ownership is implied. MMP.
};
#undef IMETHOD_VISIBILITY
#define IMETHOD_VISIBILITY default
class NS_GFX DeviceContextImpl : public nsIDeviceContext,
public nsIObserver,
public nsSupportsWeakReference
@ -140,8 +143,6 @@ public:
NS_IMETHOD SetAltDevice(nsIDeviceContext* aAltDC);
NS_IMETHOD GetAltDevice(nsIDeviceContext** aAltDC) { *aAltDC = mAltDC.get(); NS_IF_ADDREF(*aAltDC); return NS_OK;}
NS_IMETHOD SetUseAltDC(PRUint8 aValue, PRBool aOn);
#else
#endif
private:
@ -183,4 +184,7 @@ public:
#endif
};
#undef IMETHOD_VISIBILITY
#define IMETHOD_VISIBILITY hidden
#endif /* nsDeviceContext_h___ */

View File

@ -613,7 +613,7 @@ nsFontCache::~nsFontCache()
Flush();
}
NS_IMETHODIMP
nsresult
nsFontCache::Init(nsIDeviceContext* aContext)
{
NS_PRECONDITION(nsnull != aContext, "null ptr");
@ -623,7 +623,7 @@ nsFontCache::Init(nsIDeviceContext* aContext)
return NS_OK;
}
NS_IMETHODIMP
nsresult
nsFontCache::GetDeviceContext(nsIDeviceContext *&aContext) const
{
aContext = mContext;
@ -631,7 +631,7 @@ nsFontCache::GetDeviceContext(nsIDeviceContext *&aContext) const
return NS_OK;
}
NS_IMETHODIMP
nsresult
nsFontCache::GetMetricsFor(const nsFont& aFont, nsIAtom* aLangGroup,
nsIFontMetrics *&aMetrics)
{
@ -708,7 +708,7 @@ nsFontCache::GetMetricsFor(const nsFont& aFont, nsIAtom* aLangGroup,
/* PostScript and Xprint module may override this method to create
* nsIFontMetrics objects with their own classes
*/
NS_IMETHODIMP
nsresult
nsFontCache::CreateFontMetricsInstance(nsIFontMetrics** fm)
{
static NS_DEFINE_CID(kFontMetricsCID, NS_FONT_METRICS_CID);

View File

@ -31,6 +31,9 @@
//class nsIPrintSettings;
#undef IMETHOD_VISIBILITY
#define IMETHOD_VISIBILITY default
//*****************************************************************************
//*** nsPrintOptions
//*****************************************************************************
@ -76,6 +79,7 @@ protected:
static nsFont* sDefaultFont;
};
#undef IMETHOD_VISIBILITY
#define IMETHOD_VISIBILITY hidden
#endif /* nsPrintOptions_h__ */

View File

@ -48,6 +48,9 @@
//*** nsPrintSession
//*****************************************************************************
#undef IMETHOD_VISIBILITY
#define IMETHOD_VISIBILITY default
class NS_GFX nsPrintSession : public nsIPrintSession,
public nsSupportsWeakReference
{
@ -61,4 +64,7 @@ public:
virtual nsresult Init();
};
#undef IMETHOD_VISIBILITY
#define IMETHOD_VISIBILITY hidden
#endif // nsPrintSession_h__

View File

@ -33,6 +33,10 @@
//*****************************************************************************
//*** nsPrintSettings
//*****************************************************************************
#undef IMETHOD_VISIBILITY
#define IMETHOD_VISIBILITY default
class NS_GFX nsPrintSettings : public nsIPrintSettings
{
public:
@ -111,6 +115,7 @@ protected:
};
#undef IMETHOD_VISIBILITY
#define IMETHOD_VISIBILITY hidden
#endif /* nsPrintSettings_h__ */

View File

@ -51,6 +51,8 @@ typedef struct {
int i; // edge number: edge i goes from mPointList[i] to mPointList[i+1]
} Edge;
#undef IMETHOD_VISIBILITY
#define IMETHOD_VISIBILITY default
class nsRenderingContextImpl : public nsIRenderingContext
{
@ -208,6 +210,8 @@ private:
};
#undef IMETHOD_VISIBILITY
#define IMETHOD_VISIBILITY hidden
/** ---------------------------------------------------
* Class QBezierCurve, a quadratic bezier curve

View File

@ -520,11 +520,11 @@ class nsFontCachePS : public nsFontCache
{
public:
/* override DeviceContextImpl::CreateFontCache() */
NS_IMETHODIMP CreateFontMetricsInstance(nsIFontMetrics** aResult);
virtual nsresult CreateFontMetricsInstance(nsIFontMetrics** aResult);
};
NS_IMETHODIMP nsFontCachePS::CreateFontMetricsInstance(nsIFontMetrics** aResult)
nsresult nsFontCachePS::CreateFontMetricsInstance(nsIFontMetrics** aResult)
{
NS_PRECONDITION(aResult, "null out param");
nsIFontMetrics *fm = new nsFontMetricsPS();

View File

@ -523,11 +523,11 @@ class nsFontCacheXlib : public nsFontCache
{
public:
/* override DeviceContextImpl::CreateFontCache() */
NS_IMETHODIMP CreateFontMetricsInstance(nsIFontMetrics** aResult);
virtual nsresult CreateFontMetricsInstance(nsIFontMetrics** aResult);
};
NS_IMETHODIMP nsFontCacheXlib::CreateFontMetricsInstance(nsIFontMetrics** aResult)
nsresult nsFontCacheXlib::CreateFontMetricsInstance(nsIFontMetrics** aResult)
{
NS_PRECONDITION(aResult, "null out param");
nsIFontMetrics *fm = new nsFontMetricsXlib();

View File

@ -398,11 +398,11 @@ class nsFontCacheXp : public nsFontCache
{
public:
/* override DeviceContextImpl::CreateFontCache() */
NS_IMETHOD CreateFontMetricsInstance(nsIFontMetrics** aResult);
virtual nsresult CreateFontMetricsInstance(nsIFontMetrics** aResult);
};
NS_IMETHODIMP nsFontCacheXp::CreateFontMetricsInstance(nsIFontMetrics** aResult)
nsresult nsFontCacheXp::CreateFontMetricsInstance(nsIFontMetrics** aResult)
{
NS_PRECONDITION(aResult, "null out param");
nsIFontMetrics *fm = new nsFontMetricsXlib();

View File

@ -65,6 +65,9 @@ class nsICollation;
* class derived from nsMsgFolder for those folders that use an nsIMsgDatabase
*/
#undef IMETHOD_VISIBILITY
#define IMETHOD_VISIBILITY default
class NS_MSG_BASE nsMsgDBFolder: public nsRDFResource,
public nsSupportsWeakReference,
public nsIMsgFolder,
@ -247,4 +250,7 @@ protected:
static const nsStaticAtom folder_atoms[];
};
#undef IMETHOD_VISIBILITY
#define IMETHOD_VISIBILITY hidden
#endif

View File

@ -61,6 +61,9 @@ class nsIMsgProtocolInfo;
* this particular implementation is not meant to be used directly.
*/
#undef IMETHOD_VISIBILITY
#define IMETHOD_VISIBILITY default
class NS_MSG_BASE nsMsgIncomingServer : public nsIMsgIncomingServer,
public nsSupportsWeakReference
{
@ -112,4 +115,7 @@ protected:
PRPackedBool mPerformingBiff;
};
#undef IMETHOD_VISIBILITY
#define IMETHOD_VISIBILITY hidden
#endif // nsMsgIncomingServer_h__

View File

@ -62,6 +62,9 @@
//
//////////////////////////////////////////////////////////////////////////////////
#undef IMETHOD_VISIBILITY
#define IMETHOD_VISIBILITY default
class NS_MSG_BASE nsMsgMailNewsUrl : public nsIMsgMailNewsUrl
{
public:
@ -106,4 +109,7 @@ protected:
nsCOMPtr<nsIUrlListenerManager> m_urlListeners;
};
#undef IMETHOD_VISIBILITY
#define IMETHOD_VISIBILITY hidden
#endif /* nsMsgMailNewsUrl_h___ */

View File

@ -64,6 +64,9 @@ class nsIMsgMailNewsUrl;
class nsMsgFilePostHelper;
class nsIProxyInfo;
#undef IMETHOD_VISIBILITY
#define IMETHOD_VISIBILITY default
// This is a helper class used to encapsulate code shared between all of the
// mailnews protocol objects (imap, news, pop, smtp, etc.) In particular,
// it unifies the core networking code for the protocols. My hope is that
@ -250,4 +253,7 @@ protected:
virtual nsresult CloseSocket();
};
#undef IMETHOD_VISIBILITY
#define IMETHOD_VISIBILITY hidden
#endif /* nsMsgProtocol_h__ */

View File

@ -50,6 +50,10 @@
/**
* base class for all message undo/redo transactions.
*/
#undef IMETHOD_VISIBILITY
#define IMETHOD_VISIBILITY default
class NS_MSG_BASE nsMsgTxn : public nsITransaction
{
NS_DECL_ISUPPORTS
@ -78,4 +82,7 @@ protected:
nsresult CheckForToggleDelete(nsIMsgFolder *aFolder, const nsMsgKey &aMsgKey, PRBool *aResult);
};
#undef IMETHOD_VISIBILITY
#define IMETHOD_VISIBILITY hidden
#endif

View File

@ -67,6 +67,49 @@
/*----------------------------------------------------------------------*/
/* Import/export defines */
/**
* Using the visibility("hidden") attribute allows the compiler to use
* PC-relative addressing to call this function. If a function does not
* access any global data, and does not call any methods which are not either
* file-local or hidden, then on ELF systems we avoid loading the address of
* the PLT into a register at the start of the function, which reduces code
* size and frees up a register for general use.
*
* As a general rule, this should be used for any non-exported symbol
* (including virtual method implementations). NS_IMETHOD uses this by
* default; if you need to have your NS_IMETHOD functions exported, you can
* wrap your class as follows:
*
* #undef IMETHOD_VISIBILITY
* #define IMETHOD_VISIBILITY default
* class Foo {
* ...
* };
*
* #undef IMETHOD_VISIBILITY
* #define IMETHOD_VISIBILITY hidden
*
* Don't forget to change the visibility back to hidden before the end
* of a header!
*/
#ifdef HAVE_VISIBILITY_ATTRIBUTE
#define NS_VISIBILITY_(vis) __attribute__ ((visibility (#vis)))
#define NS_HIDDEN_(type) type NS_VISIBILITY(hidden)
#else
#define NS_VISIBILITY_(vis)
#define NS_HIDDEN_(type) type
#endif
#define NS_HIDDEN NS_VISIBILITY(hidden)
#undef IMETHOD_VISIBILITY
#define IMETHOD_VISIBILITY hidden
/* Extra layer of macro expansion to allow IMETHOD_VISIBILITY to be
stringified. */
#define NS_VISIBILITY(vis) NS_VISIBILITY_(vis)
#ifdef NS_WIN32
#define NS_IMPORT __declspec(dllimport)
@ -97,7 +140,7 @@
#define NS_IMPORT_(type) type
#define NS_EXPORT
#define NS_EXPORT_(type) type
#define NS_IMETHOD_(type) virtual type
#define NS_IMETHOD_(type) virtual type NS_VISIBILITY(IMETHOD_VISIBILITY)
#define NS_IMETHODIMP_(type) type
#define NS_METHOD_(type) type
#define NS_CALLBACK_(_type, _name) _type (* _name)

View File

@ -44,6 +44,9 @@
static const PRUint32 kAutoArraySize = 8;
#undef IMETHOD_VISIBILITY
#define IMETHOD_VISIBILITY default
class NS_COM nsSupportsArray : public nsISupportsArray {
public:
nsSupportsArray(void);
@ -163,4 +166,7 @@ private:
nsSupportsArray(const nsISupportsArray& other);
};
#undef IMETHOD_VISIBILITY
#define IMETHOD_VISIBILITY hidden
#endif // nsSupportsArray_h__

View File

@ -29,6 +29,9 @@
class nsWeakReference;
#undef IMETHOD_VISIBILITY
#define IMETHOD_VISIBILITY default
class NS_COM nsSupportsWeakReference : public nsISupportsWeakReference
{
public:
@ -61,6 +64,9 @@ class NS_COM nsSupportsWeakReference : public nsISupportsWeakReference
PRBool HasWeakReferences() const {return mProxy != 0;}
};
#undef IMETHOD_VISIBILITY
#define IMETHOD_VISIBILITY hidden
class NS_COM nsWeakReference : public nsIWeakReference
{
public:

View File

@ -186,6 +186,9 @@ struct nsXPTCVariant : public nsXPTCMiniVariant
/***************************************************************************/
#undef IMETHOD_VISIBILITY
#define IMETHOD_VISIBILITY default
class nsXPTCStubBase : public nsISupports
{
public:
@ -211,6 +214,8 @@ public:
nsXPTCMiniVariant* params) = 0;
};
#undef IMETHOD_VISIBILITY
#define IMETHOD_VISIBILITY hidden
PR_BEGIN_EXTERN_C