[Lldb-commits] [lldb] r105746 - /lldb/trunk/include/lldb/lldb-enumerations.h

Greg Clayton gclayton at apple.com
Wed Jun 9 23:33:13 PDT 2010


Eli,

Can you change this back to somehow use some sort of #ifdeffery on linux? We had a working version for Mac OS X, there must be an easy way to do this for linux.

Shared libraries at Apple are not supposed to have any global init constructors in them (we have an build exception for this right now for other things inside LLVM that have global init ctors) but we would like to avoid adding any in the LLDB codebase if at all possible. Also we would like to avoid defining a constant in a header file.

We should probably modify the Host.h time to somehow autodetect this and set the define appropriately.

We currently add the "-Wglobal-constructors" to all C++ compiles to see these issues as they arise.

/Volumes/work/gclayton/Documents/src/lldb/include/lldb/lldb-enumerations.h:86:0 /Volumes/work/gclayton/Documents/src/lldb/include/lldb/lldb-enumerations.h:86: warning: 'lldb::eByteOrderHost' requires global construction


You will see some code (which can sometimes get ugly) around LLDB that deals with avoiding global constructors. 

The above example below from SymbolFileDWARF.cpp shows a way to have a static variable in a source file without having to have a global init ctor:

static const ConstString&
GetSectionNameDebugInfo()
{
    static const ConstString g_sect_name("__debug_info");
    return g_sect_name;
}

There are also some ugly examples where multiple functions must access a static and a GetAndSet function is made. One such example is in Log.cpp:

static Stream *
StreamForSTDOUTAccess (bool set, StreamSP &stream_sp);

Let me know if you can make the changes for linux, else I might need to back out the change.

Greg Clayton


On Jun 9, 2010, at 12:26 PM, Eli Friedman wrote:

> Author: efriedma
> Date: Wed Jun  9 14:26:51 2010
> New Revision: 105746
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=105746&view=rev
> Log:
> Use portable endianness routine from LLVM.
> 
> 
> Modified:
>    lldb/trunk/include/lldb/lldb-enumerations.h
> 
> Modified: lldb/trunk/include/lldb/lldb-enumerations.h
> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-enumerations.h?rev=105746&r1=105745&r2=105746&view=diff
> ==============================================================================
> --- lldb/trunk/include/lldb/lldb-enumerations.h (original)
> +++ lldb/trunk/include/lldb/lldb-enumerations.h Wed Jun  9 14:26:51 2010
> @@ -10,6 +10,8 @@
> #ifndef LLDB_enumerations_h_
> #define LLDB_enumerations_h_
> 
> +#include "llvm/System/Host.h"
> +
> namespace lldb {
> 
> //----------------------------------------------------------------------
> @@ -71,18 +73,18 @@
>     eByteOrderInvalid   = 0,
>     eByteOrderLittle    = 1234,
>     eByteOrderBig       = 4321,
> -    eByteOrderPDP       = 3412,
> -#if   defined (__LITTLE_ENDIAN__)
> -    eByteOrderHost      = eByteOrderLittle
> -#elif defined (__BIG_ENDIAN__)
> -    eByteOrderHost      = eByteOrderBig
> -#elif defined (__PDP_ENDIAN__)
> -    eByteOrderHost      = eByteOrderPDP
> -#else
> -#error unable to detect endianness
> -#endif
> +    eByteOrderPDP       = 3412
> } ByteOrder;
> 
> +inline ByteOrder getHostByteOrder() {
> +  if (llvm::sys::isLittleEndianHost())
> +    return eByteOrderLittle;
> +  return eByteOrderBig;
> +}
> +
> +// FIXME: Replace uses of eByteOrderHost with getHostByteOrder()!
> +const ByteOrder eByteOrderHost = getHostByteOrder();
> +
> //----------------------------------------------------------------------
> // Register encoding definitions
> //----------------------------------------------------------------------
> 
> 
> _______________________________________________
> lldb-commits mailing list
> lldb-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20100609/154d653a/attachment.html>


More information about the lldb-commits mailing list