Closed Bug 449373 Opened 16 years ago Closed 9 months ago

firefox3 FreeBSD Alpha build fails -> nsTHashtable.h:368: warning: cast from increases required alignment of target type

Categories

(Core :: XPCOM, defect)

DEC
FreeBSD
defect

Tracking

()

RESOLVED WONTFIX

People

(Reporter: mexas, Unassigned)

Details

Attachments

(1 file)

User-Agent:       Mozilla/5.0 (X11; U; FreeBSD alpha; en-US; rv:1.8.1.16) Gecko/20080801 Firefox/2.0.0.16
Build Identifier: build fails - firefox 3.0.1 on FreeBSD alpha

I'm building firefox3.0.1 on FreeBSD-6.3-stable Alpha.
I get this error message:

gmake[5]: Entering directory `/usr/ports/www/firefox3/work/mozilla/netwerk/cookie/src'
nsCookieService.cpp
c++ -o nsCookieService.o -c  -DMOZILLA_INTERNAL_API -D_IMPL_NS_COM -DEXPORT_XPT_API -DEXPORT_XPTC_API -D_IMPL_NS_COM_OBSOLETE -D_IMPL_NS_GFX -D_IMPL_NS_WIDGET -DIMPL_XREAPI -DIMPL_NS_NET -DIMPL_THEBES  -DOSTYPE=\"FreeBSD6\" -DOSARCH=FreeBSD -DIMPL_NS_NET  -I. -I. -I../../../dist/include/xpcom -I../../../dist/include/string -I../../../dist/include/pref -I../../../dist/include/storage -I../../../dist/include   -I../../../dist/include/necko -I/usr/local/include/nspr   -I/usr/include  -I../../../dist/sdk/include -I/usr/local/include   -fPIC  -I/usr/local/include  -I/usr/local/include -fno-rtti -fno-exceptions -Wall -Wconversion -Wpointer-arith -Woverloaded-virtual -Wsynth -Wno-ctor-dtor-privacy -Wno-non-virtual-dtor -Wcast-align -Wno-long-long -O -pipe -mcpu=ev6 -mieee -O2 -fno-strict-aliasing -fno-strict-aliasing -fshort-wchar -pipe  -DNDEBUG -DTRIMMED -O -Werror  -I/usr/local/include  -I/usr/local/include -DMOZILLA_CLIENT -include ../../../mozilla-config.h nsCookieService.cpp
../../../dist/include/xpcom/nsTHashtable.h: In static member function `static PRBool nsTHashtable<EntryType>::s_MatchEntry(PLDHashTable*, const PLDHashEntryHdr*, const void*) [with EntryType = nsCookieEntry]':
../../../dist/include/xpcom/nsTHashtable.h:335:   instantiated from `PRBool nsTHashtable<EntryType>::Init(PRUint32) [with EntryType = nsCookieEntry]'
nsCookieService.cpp:418:   instantiated from here
../../../dist/include/xpcom/nsTHashtable.h:368: warning: cast from `const PLDHashEntryHdr*' to `const nsCookieEntry*' increases required alignment of target type
gmake[5]: *** [nsCookieService.o] Error 1



Reproducible: Always

Steps to Reproduce:
1. get FreeBSD-6.3-Alpha
2. cd /usr/ports/www/firefox3
3. make
Actual Results:  
../../../dist/include/xpcom/nsTHashtable.h:368: warning: cast from `const PLDHashEntryHdr*' to `const nsCookieEntry*' increases required alignment of target type

I believe this warning indicates a problem that leads to failure of compilation of nsCookieService.cpp
Summary: nsTHashtable.h:368: warning: cast from increases required alignment of target type → firefox3 FreeBSD Alpha build fails -> nsTHashtable.h:368: warning: cast from increases required alignment of target type
This is an interesting bug, and it may be "real" in some sense. nsTHashtable is a wrapper around the pldhash code, which places entries (which begin with or are derived from PLDHashEntryHdr) in a contiguous array. It uses sizeof(entry) as the entry size, which may not be the same as the required alignment for the entry type.

What is the required alignment of nsCookieEntry and PLDHashEntryHdr? Is there a way for the compiler to tell us what the required alignment is? If so, we may need to extend the entry size to the required alignment. In that case we "know" that the PLDHashEntryHdr* is of the required alignment, and this cast should be safe... then how do we tell the compiler that it's a safe cast?

In an private mail from Anton he says that this worked in FF2 but broke in FF3 because previously we were using NS_REINTERPRET_CAST and we're now using reinterpret_cast<>(), but these should have been equivalent on any modern C++ compiler.

Also, it seems like this could be a static_cast instead of a reinterpret_cast, since in nsTHashtable the entry types are always derivatives. I can provide a patch to that effect to see if it helps.
Status: UNCONFIRMED → NEW
Component: Build Config → XPCOM
Ever confirmed: true
Product: Firefox → Core
QA Contact: build.config → xpcom
Anton, please try this patch and let me know whether it helps.
Assignee: nobody → benjamin
Status: NEW → ASSIGNED
Benjamin, I haven't dealt with patches before.
How should I call the file, and where should I place it?

anton
I saved the patch into
/usr/ports/www/firefox3/work/mozilla/xpcom/glue/ns/nsTHashtable.h.patch

Then I did

# patch < nsTHashtable.h.patch 
Hmm...  Looks like a unified diff to me...
The text leading up to this was:
--------------------------
|diff --git a/xpcom/glue/nsTHashtable.h b/xpcom/glue/nsTHashtable.h
|--- a/xpcom/glue/nsTHashtable.h
|+++ b/xpcom/glue/nsTHashtable.h
--------------------------
Patching file nsTHashtable.h using Plan A...
Hunk #1 succeeded at 157 (offset -6 lines).
Hunk #2 succeeded at 355 (offset -6 lines).
Hunk #3 succeeded at 365 (offset -6 lines).
Hunk #4 succeeded at 375 (offset -6 lines).
Hunk #5 succeeded at 387 (offset -6 lines).
Hunk #6 succeeded at 396 (offset -6 lines).
Hunk #7 succeeded at 408 (offset -6 lines).
Hmm...  Ignoring the trailing garbage.
done
#

The error message is very similar, if not the same:

gmake[5]: Entering directory `/usr/ports/www/firefox3/work/mozilla/netwerk/cookie/src'
nsCookieService.cpp
c++ -o nsCookieService.o -c  -DMOZILLA_INTERNAL_API -D_IMPL_NS_COM -DEXPORT_XPT_API -DEXPORT_XPTC_API -D_IMPL_NS_COM_OBSOLETE -D_IMPL_NS_GFX -D_IMPL_NS_WIDGET -DIMPL_XREAPI -DIMPL_NS_NET -DIMPL_THEBES  -DOSTYPE=\"FreeBSD6\" -DOSARCH=FreeBSD -DIMPL_NS_NET  -I. -I. -I../../../dist/include/xpcom -I../../../dist/include/string -I../../../dist/include/pref -I../../../dist/include/storage -I../../../dist/include   -I../../../dist/include/necko -I/usr/local/include/nspr   -I/usr/include  -I../../../dist/sdk/include -I/usr/local/include   -fPIC  -I/usr/local/include  -I/usr/local/include -fno-rtti -fno-exceptions -Wall -Wconversion -Wpointer-arith -Woverloaded-virtual -Wsynth -Wno-ctor-dtor-privacy -Wno-non-virtual-dtor -Wcast-align -Wno-long-long -O -pipe -mcpu=ev6 -mieee -O2 -fno-strict-aliasing -fno-strict-aliasing -fshort-wchar -pipe  -DNDEBUG -DTRIMMED -O -Werror  -I/usr/local/include  -I/usr/local/include -DMOZILLA_CLIENT -include ../../../mozilla-config.h nsCookieService.cpp
../../../dist/include/xpcom/nsTHashtable.h: In static member function `static PRBool nsTHashtable<EntryType>::s_MatchEntry(PLDHashTable*, const PLDHashEntryHdr*, const void*) [with EntryType = nsCookieEntry]':
../../../dist/include/xpcom/nsTHashtable.h:334:   instantiated from `PRBool nsTHashtable<EntryType>::Init(PRUint32) [with EntryType = nsCookieEntry]'
nsCookieService.cpp:418:   instantiated from here
../../../dist/include/xpcom/nsTHashtable.h:367: warning: cast from `const PLDHashEntryHdr*' to `const nsCookieEntry*' increases required alignment of target type
gmake[5]: *** [nsCookieService.o] Error 1

thanks
anton
Also, in case it matters, the compiler versions are:

# gcc -v
Using built-in specs.
Configured with: FreeBSD/alpha system compiler
Thread model: posix
gcc version 3.4.6 [FreeBSD] 20060305
#

# gcc42 -v
Using built-in specs.
Target: alpha-portbld-freebsd6.3
Configured with: ./..//gcc-4.2-20080702/configure --disable-nls --with-system-zlib --with-libiconv-prefix=/usr/local --with-gmp=/usr/local --program-suffix=42 --libdir=/usr/local/lib/gcc-4.2.5 --with-gxx-include-dir=/usr/local/lib/gcc-4.2.5/include/c++/ --disable-libgcj --prefix=/usr/local --mandir=/usr/local/man --infodir=/usr/local/info/gcc42 alpha-portbld-freebsd6.3
Thread model: posix
gcc version 4.2.5 20080702 (prerelease)
#

I believe freebsd3 port is being built with the system compiler, i.e. 3.4.6.

anton
In that case, I do not know how to fix this bug... I'm almost certain the error is bogus, since we know that the PLDHashEntryHdr* is the correct alignment (confirmed using sizeof()), but I don't know how to inform the compiler that this cast should be allowed.
How do you confirm alignment with sizeof?
From experiments, it seems that sizeof(struct) is always a multiple of the necessary alignment for that struct.

The pldhash entry store is malloced (which has perfect alignment) and entries are on sizeof(struct) boundaries within the allocation, so I believe that in reality they are always correctly aligned.

Shaver says: "I guess you want to cast via void*"... which makes me sad!
I received the following advice from freebsd-alpha mailing list:

"Just accept the warnings.
Mozilla also always had some missaligned acces in it.
Fortunately we can correct missaligned access in userland and they are
not too much so you can live with them.
Especially since they said that the pointer always has the required
alignment.
The real bug is that they cast pointers of completely different types.
You can work around by increasing the alignemnt requirement of
PLDHashEntryHdr's type, so the compiler knows that."

Does this make sense to you?
If yes, how do I 'increase the alignment requirement of PLDHashEntryHdr type'?

anton
If I compile nsCookieService.cpp with g++42 (version 4.2.5) instead of the default system c++ (version 3.4.6), the aligning warning is different:

# g++42 -o nsCookieService.o -c -DMOZILLA_INTERNAL_API -D_IMPL_NS_COM -DEXPORT_XPT_API -DEXPORT_XPTC_API -D_IMPL_NS_COM_OBSOLETE -D_IMPL_NS_GFX -D_IMPL_NS_WIDGET -DIMPL_XREAPI -DIMPL_NS_NET -DIMPL_THEBES -DOSTYPE=\"FreeBSD6\" -DOSARCH=FreeBSD -DIMPL_NS_NET -I. -I. -I../../../dist/include/xpcom -I../../../dist/include/string -I../../../dist/include/pref -I../../../dist/include/storage -I../../../dist/include -I../../../dist/include/necko -I/usr/local/include/nspr -I/usr/include -I../../../dist/sdk/include -I/usr/local/include -fPIC -I/usr/local/include -I/usr/local/include -fno-rtti -fno-exceptions -Wall -Wconversion -Wpointer-arith -Woverloaded-virtual -Wsynth -Wno-ctor-dtor-privacy -Wno-non-virtual-dtor -Wcast-align -Wno-long-long -O -pipe -mcpu=ev6 -mieee -O2 -fno-strict-aliasing -fno-strict-aliasing -fshort-wchar -pipe -DNDEBUG -DTRIMMED -O -Werror -I/usr/local/include -I/usr/local/include -DMOZILLA_CLIENT -include ../../../mozilla-config.h nsCookieService.cpp
cc1plus: warnings being treated as errors
In file included from ../../../dist/include/xpcom/nsCOMArray.h:42,
                 from nsCookieService.cpp:56:
../../../dist/include/xpcom/nsVoidArray.h: In member function 'void nsAutoVoidArray::ResetToAutoBuffer()':
../../../dist/include/xpcom/nsVoidArray.h:193: warning: cast from 'char*' to 'nsVoidArray::Impl*' increases required alignment of target type
#

Looking at nsVoidArray.h Impl seems to be a structure with 2 int and 1 boolean:

    135   struct Impl {
    136     /**
    137      * Packed bits. The low 30 bits are the array's size.
    138      * The two highest bits indicate whether or not we "own" mImpl and
    139      * must free() it when destroyed, and whether we have a preallocated
    140      * nsAutoVoidArray buffer.
    141      */
    142     PRUint32 mBits;
    143
    144     /**
    145      * The number of elements in the array
    146      */
    147     PRInt32 mCount;
    148
    149     /**
    150      * Array data, padded out to the actual size of the array.
    151      */
    152     void*   mArray[1];
    153   };

the problem bit:

    186 // A zero-based array with a bit of automatic internal storage
    187 class NS_COM_GLUE nsAutoVoidArray : public nsVoidArray {
    188 public:
    189   nsAutoVoidArray();
    190
    191   void ResetToAutoBuffer()
    192   {
--> 193     SetArray(reinterpret_cast<Impl*>(mAutoBuf),kAutoBufSize,0,PR_FALSE,
    194              PR_TRUE);
    195   }
    196  
    197 protected:
    198   // The internal storage
    199   char mAutoBuf[sizeof(Impl) + (kAutoBufSize - 1) * sizeof(void*)];
    200 };

Why different warning for c++ and g++42?
This warning seems to be quite serious, casting 2 int and a boolean to char.
Is it supposed to be like this?

many thanks
anton
I tried to rebuld everything using gcc42. I still get stopped at the same point, but now I get some more warnings:

nsCookieService.cpp
g++42 -o nsCookieService.o -c -fvisibility=hidden -DMOZILLA_INTERNAL_API -D_IMPL_NS_COM -DEXPORT_XPT_API -DEXPORT_XPTC_API -D_IMPL_NS_COM_OBSOLETE -D_IMPL_NS_GFX -D_IMPL_NS_WIDGET -DIMPL_XREAPI -DIMPL_NS_NET -DIMPL_THEBES  -DOSTYPE=\"FreeBSD6\" -DOSARCH=FreeBSD -DIMPL_NS_NET  -I. -I. -I../../../dist/include/xpcom -I../../../dist/include/string -I../../../dist/include/pref -I../../../dist/include/storage -I../../../dist/include   -I../../../dist/include/necko -I/usr/local/include/nspr   -I/usr/include  -I../../../dist/sdk/include -I/usr/local/include   -fPIC  -I/usr/local/include  -I/usr/local/include -fno-rtti -fno-exceptions -Wall -Wconversion -Wpointer-arith -Woverloaded-virtual -Wsynth -Wno-ctor-dtor-privacy -Wno-non-virtual-dtor -Wcast-align -Wno-long-long -O -pipe -mcpu=ev6 -mieee -O2 -fno-strict-aliasing -fno-strict-aliasing -fshort-wchar -pipe  -DNDEBUG -DTRIMMED -O -Werror  -I/usr/local/include  -I/usr/local/include -DMOZILLA_CLIENT -include ../../../mozilla-config.h nsCookieService.cpp
cc1plus: warnings being treated as errors
In file included from ../../../dist/include/xpcom/nsCOMArray.h:42,
                 from nsCookieService.cpp:56:
../../../dist/include/xpcom/nsVoidArray.h: In member function 'void nsAutoVoidArray::ResetToAutoBuffer()':
../../../dist/include/xpcom/nsVoidArray.h:193: warning: cast from 'char*' to 'nsVoidArray::Impl*' increases required alignment of target type
../../../dist/include/xpcom/nsTHashtable.h: In member function 'EntryType* nsTHashtable<EntryType>::GetEntry(typename EntryType::KeyType) const [with EntryType = nsCookieEntry]':
nsCookieService.cpp:1160:   instantiated from here
../../../dist/include/xpcom/nsTHashtable.h:164: warning: cast from 'PLDHashEntryHdr*' to 'nsCookieEntry*' increases required alignment of target type
../../../dist/include/xpcom/nsTHashtable.h: In static member function 'static void nsTHashtable<EntryType>::s_ClearEntry(PLDHashTable*, PLDHashEntryHdr*) [with EntryType = nsCookieEntry]':
../../../dist/include/xpcom/nsTHashtable.h:335:   instantiated from 'PRBool nsTHashtable<EntryType>::Init(PRUint32) [with EntryType = nsCookieEntry]'
nsCookieService.cpp:418:   instantiated from here
../../../dist/include/xpcom/nsTHashtable.h:391: warning: cast from 'PLDHashEntryHdr*' to 'nsCookieEntry*' increases required alignment of target type
../../../dist/include/xpcom/nsTHashtable.h: In static member function 'static void nsTHashtable<EntryType>::s_CopyEntry(PLDHashTable*, const PLDHashEntryHdr*, PLDHashEntryHdr*) [with EntryType = nsCookieEntry]':
../../../dist/include/xpcom/nsTHashtable.h:339:   instantiated from 'PRBool nsTHashtable<EntryType>::Init(PRUint32) [with EntryType = nsCookieEntry]'
nsCookieService.cpp:418:   instantiated from here
../../../dist/include/xpcom/nsTHashtable.h:379: warning: cast from 'const PLDHashEntryHdr*' to 'const nsCookieEntry*' increases required alignment of target type
../../../dist/include/xpcom/nsTHashtable.h: In static member function 'static PLDHashOperator nsTHashtable<EntryType>::s_EnumStub(PLDHashTable*, PLDHashEntryHdr*, PRUint32, void*) [with EntryType = nsCookieEntry]':
../../../dist/include/xpcom/nsTHashtable.h:235:   instantiated from 'PRUint32 nsTHashtable<EntryType>::EnumerateEntries(PLDHashOperator (*)(EntryType*, void*), void*) [with EntryType = nsCookieEntry]'
nsCookieService.cpp:819:   instantiated from here
../../../dist/include/xpcom/nsTHashtable.h:414: warning: cast from 'PLDHashEntryHdr*' to 'nsCookieEntry*' increases required alignment of target type
gmake[5]: *** [nsCookieService.o] Error 1


I got tons of "increases required alignment of target type" warnings up to that point, but here "warnings being treated as errors". Why?

thanks
anton
These are warnings. They are *probably* harmless. To turn off warnings-as-errors for this directory, do:

make WARNINGS_AS_ERRORS=
Severity: critical → minor
Assignee: benjamin → nobody
Status: ASSIGNED → NEW
Severity: minor → S4

Surely this can be closed? It's 15 years old, FreeBSD doesn't even support alpha anymore?

Sounds reasonable to close this.

Status: NEW → RESOLVED
Closed: 9 months ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: