BenVim / rapidjson

Automatically exported from code.google.com/p/rapidjson
MIT License
1 stars 0 forks source link

[address alignment issue]tutorial.cpp isn't working on HP-UX 11.23 ia64 #115

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. build and run tutorial.cpp 

What is the expected output? What do you see instead?
Expected to see normal tutorial.cpp output. Instead, bus error (core dumped) 
occurred. 

What version of the product are you using? On what operating system?
rapidjson 1.1 on HP-UX B.11.23 U ia64 2680631136. GCC version 3.4.5

Please provide any additional information below.
1. bt
Program received signal SIGBUS, Bus error
  si_code: 1 - BUS_ADRALN - Invalid address alignment. Please refer to the following link that helps in handling unaligned data: http://docs.hp.com/en/7730/newhelp0610/pragmas.htm#pragma-pack-ex3.
0x400b551 in 
rapidjson::GenericValue<rapidjson::UTF8<char>,rapidjson::MemoryPoolAllocator<rap
idjson::CrtAllocator> >::GenericValue(rapidjson::Type)+0x41 ()
(gdb) bt
#0  0x400b551 in 
rapidjson::GenericValue<rapidjson::UTF8<char>,rapidjson::MemoryPoolAllocator<rap
idjson::CrtAllocator> >::GenericValue(rapidjson::Type)+0x41 ()
#1  0x4009ce0 in 
rapidjson::GenericDocument<rapidjson::UTF8<char>,rapidjson::MemoryPoolAllocator<
rapidjson::CrtAllocator> >::StartObject()+0xe0 ()
#2  0x40092b0 in 
rapidjson::GenericReader<rapidjson::UTF8<char>,rapidjson::MemoryPoolAllocator<ra
pidjson::CrtAllocator> >::ParseObject<(unsigned 
int)0,rapidjson::GenericStringStream<rapidjson::UTF8<char> 
>,rapidjson::GenericDocument<rapidjson::UTF8<char>,rapidjson::MemoryPoolAllocato
r<rapidjson::CrtAllocator> > 
>(rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>&,< (NOT IMPLEMENTED) 
>&)
   +0x130 ()
#3  0x4008510 in 
rapidjson::GenericReader<rapidjson::UTF8<char>,rapidjson::MemoryPoolAllocator<ra
pidjson::CrtAllocator> >::Parse<(unsigned 
int)0,rapidjson::GenericStringStream<rapidjson::UTF8<char> 
>,rapidjson::GenericDocument<rapidjson::UTF8<char>,rapidjson::MemoryPoolAllocato
r<rapidjson::CrtAllocator> > 
>(rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>&,< (NOT IMPLEMENTED) 
>&)+0x3e0 ()
#4  0x4007470 in 
rapidjson::GenericDocument<rapidjson::UTF8<char>,rapidjson::MemoryPoolAllocator<
rapidjson::CrtAllocator> >::ParseStream<(unsigned 
int)0,rapidjson::GenericStringStream<rapidjson::UTF8<char> > 
>(rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>&)+0xe0 ()
#5  0x4006d70 in 
rapidjson::GenericDocument<rapidjson::UTF8<char>,rapidjson::MemoryPoolAllocator<
rapidjson::CrtAllocator> >::Parse<(unsigned int)0>(char const*)+0xb0 ()
#6  0x4006490:0 in main+0x230 ()

2. In StartObject(), function Push returns "0x4001941c"

Original issue reported on code.google.com by zro...@gmail.com on 15 Sep 2014 at 9:33

GoogleCodeExporter commented 8 years ago
Thank you so much for your wonderful json library. We need a cross-platform 
json library. So far, rapidjson works fine on Redhat/Solaris/AIX in our 
project. Still we need to implement it on HP-UX, both IA64 and PA 64. Please 
give any clue for this issue. Many thanks.

Original comment by zro...@gmail.com on 15 Sep 2014 at 9:38

GoogleCodeExporter commented 8 years ago
Hi. 
Can you download a snapshot from https://github.com/miloyip/rapidjson and take 
a try?

Original comment by milo...@gmail.com on 15 Sep 2014 at 10:12

GoogleCodeExporter commented 8 years ago
Hi,
Thank you so much for your quick response. I tried the snapshot from 
https://github.com/miloyip/rapidjson first. But I found there are quite some 
errors and warning on redhat(GCC 3.2.3). I guessed there are some new features 
in C++ which are used in rapidjson 2.0 and the old GCC(3.2.3) doesn't support 
them. So I chose rapidjson 1.1 instead.
Anyway, I found the root cause for invalid address alignment on hp-ux today.
1. sizeof(ChunkHeader)==12. It causes that variable buffer in function Malloc 
is not aligning to 8. And it is not allowed to access an int64 at such an 
address on hp-ux.
*** temporary fix on hp-ux:
    struct ChunkHeader {
        size_t capacity;    //!< Capacity of the chunk in bytes (excluding the header itself).
        size_t size;        //!< Current size of allocated memory in bytes.
        ChunkHeader *next;  //!< Next chunk in the linked list.
        size_t padding;   //rock: need one size_t for alignment
    }; 

2. In function Malloc, size is aligned to 4 but not 8. It may also causes that 
variable buffer in function Malloc is not aligning to 8.
** temporary fix on hp-ux
    void* Malloc(size_t size) {
        size = (size + 7) & ~7; // Force aligning size to 8
        if (chunkHead_->size + size > chunkHead_->capacity)
            AddChunk(chunk_capacity_ > size ? chunk_capacity_ : size);
        char *buffer = (char *)(chunkHead_ + 1) + chunkHead_->size;
        RAPIDJSON_ASSERT(((uintptr_t)buffer & 7) == 0); // returned buffer is aligned to 8
        chunkHead_->size += size;
        return buffer;
    }

I am not sure whether the fix is complete and won't cause other errors. But it 
is now working fine on hp-ux. Are there any official fix for this issue or the 
new version has already done with it?
Thanks again!

Original comment by zro...@gmail.com on 16 Sep 2014 at 10:25

GoogleCodeExporter commented 8 years ago
Thank you for your feedback.

I will check whether the Github versions need such modification (maybe via 
macros) but the version in code.google.com shall not be updated.

I will also check whether it is possible to be compatible with older gcc 
version (you may help on this as well).

Original comment by milo...@gmail.com on 17 Sep 2014 at 10:29

GoogleCodeExporter commented 8 years ago
Thank you so much! It would be my pleasure if anything I can help.

Original comment by zro...@gmail.com on 17 Sep 2014 at 2:53