Alignment fault in pvDataCPP

Bug #1754787 reported by Till Straumann
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
EPICS Base
Fix Released
Undecided
mdavidsaver

Bug Description

We experienced a (reproduceable) crash of pvData on RTEMS/powerpc.

I tracked it down to the ByteBuffer (de-)serialization code which
does IMHO ugly things:

class ByteBuffer {
  char *position;

  ...

  template <typename T>
  inline void put(T value)
  {
    ...
    *((T*)position) = value;
  }
};

PLEASE: don't code like this.

The template was instantiated for a 'double' value and -- since this is a 'byte buffer' -- it is obvious that the 'position' pointer does not meet any alignment constraints.

The PowerPC (and possibly other machines, too) cannot store floating-point registers to unaligned addresses and the type cast invites the compiler to generate inappropriate code (claiming that 'position' is a valid 'double*' which in fact is not necessarily true).

During compilation I had also seen several 'breaking strict alias rule' warnings flying by (albeit not for this particular code, of course) -- but after seeing the above code I would recommend to study such warnings carefully.

Revision history for this message
Till Straumann (strauman) wrote :
Revision history for this message
mdavidsaver (mdavidsaver) wrote :

> ByteBuffer (de-)serialization code which does IMHO ugly things:

Agreed...

Can you provide a stack-trace?

Revision history for this message
mdavidsaver (mdavidsaver) wrote :

Also, a stack trace should clarify where bug report(s) should be opened. The ByteBuffer code, and most of the serialization code which calls it, lives in https://github.com/epics-base/pvDataCPP.

Revision history for this message
mdavidsaver (mdavidsaver) wrote :
Revision history for this message
Till Straumann (strauman) wrote : Re: [Bug 1754787] Re: Alignment fault in pvDataCPP

On 03/11/2018 10:49 AM, mdavidsaver wrote:
>> ByteBuffer (de-)serialization code which does IMHO ugly things:
> Agreed...
>
> Can you provide a stack-trace?
>

The faulting instruction (powerpc) is:

  9c:   db e8 00 00     stfd    f31,0(r8)

in ByteBuffer::put().

The stack trace goes like this (no line information, sorry - had to
disassemble by hand)

epics::pvData::PVScalarValue<double>::serialize(epics::pvData::ByteBuffer*,
epics::pvData::SerializableControl*) const
epics::pvData::PVStructure::serialize(epics::pvData::ByteBuffer*,
epics::pvData::SerializableControl*) const
epics::pvData::PVStructure::serialize(epics::pvData::ByteBuffer*,
epics::pvData::SerializableControl*, epics::pvData::BitSet*) const
epics::pvAccess::ServerChannelGetRequesterImpl::send(epics::pvData::ByteBuffer*,
epics::pvAccess::TransportSendControl*)
epics::pvAccess::detail::AbstractCodec::processSender(std::tr1::shared_ptr<epics::pvAccess::TransportSender>
const&)
epics::pvAccess::detail::AbstractCodec::processSendQueue()
epics::pvAccess::detail::AbstractCodec::processWrite()
epics::pvAccess::detail::BlockingTCPTransportCodec::sendThread()
epics::pvData::detail::MethRunner<epics::pvAccess::detail::BlockingTCPTransportCodec>::run()
epicsThreadCallEntryPoint()
threadWrapper()
...

HTH
- Till

Andrew Johnson (anj)
Changed in epics-base:
assignee: nobody → mdavidsaver (mdavidsaver)
status: New → Triaged
Changed in epics-base:
milestone: none → 7.0.2
status: Triaged → Fix Committed
Andrew Johnson (anj)
Changed in epics-base:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.