This is the mail archive of the gcc-prs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

c/7847: pragma pack / attribute(packed): unaligned access to packed structure on SPARC


>Number:         7847
>Category:       c
>Synopsis:       pragma pack / attribute(packed): unaligned access to packed structure on SPARC
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Fri Sep 06 05:26:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Jürgen Keil
>Release:        gcc-3.2
>Organization:
>Environment:
Solaris 8 SPARC (also seen on Debian GNU/Linux 3.0)

Problem observed at least with gcc3.2, gcc3.1 and gcc2.95.X:

Reading specs from /usr/local/gcc-3.2/lib/gcc-lib/sparc-sun-solaris2.8/3.2/specs
Configured with: ../gcc-3.2/configure --enable-languages=c,c++ --prefix=/usr/local/gcc-3.2
Thread model: posix
gcc version 3.2

Reading specs from /opt/sfw/lib/gcc-lib/sparc-sun-solaris2.8/2.95.3/specs
gcc version 2.95.3 20010315 (release)

Reading specs from /usr/lib/gcc-lib/sparc-linux/2.95.4/specs
gcc version 2.95.4 20011002 (Debian prerelease)
>Description:
GCC generates wrong code to access packed structure members
on the SPARC architecture.

A 32-bit load instruction is used to read from an unaligned
address inside a packed structure.  This is not allowed on the
SPARC architecture and the process terminates with a SIGBUS 
signal.
>How-To-Repeat:
Compile and run the attached test case

% gcc -o open3 open3.c
% ./open3
Bus error (core dumped)

Expected result:  the program should run without getting
a SIGBUS signal.

The crash happens while evaluating the |if (...)|
expression in function dvd_read_sector.  A 32-bit load
instruction is used to access the |.address| member from an 
unaligned address.

( Note:  when the member |a| inside the structure
|dvd_priv_t| is deleted, the generated code is OK; the
unaligned / packed structure is read using four byte loads.
These four bytes are assembled using 'shift' and 'or'
operations into a 32-bit value. )
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="open3.c"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="open3.c"

dHlwZWRlZiBjaGFyIGludDhfdDsKdHlwZWRlZiBzaG9ydCBpbnQxNl90Owp0eXBlZGVmIGludCBp
bnQzMl90Owp0eXBlZGVmIHVuc2lnbmVkIGNoYXIgdWludDhfdDsKdHlwZWRlZiB1bnNpZ25lZCBz
aG9ydCB1aW50MTZfdDsKdHlwZWRlZiB1bnNpZ25lZCBpbnQgdWludDMyX3Q7CgoKI2lmbmRlZiBf
X0dOVUNfXwojZGVmaW5lIF9fYXR0cmlidXRlX18oeCkKI3ByYWdtYSBwYWNrKDIpCiNlbmRpZgoK
dHlwZWRlZiBzdHJ1Y3QgewogICAgdWludDMyX3QgYWRkcmVzczsKICAgIHVpbnQxNl90IHNpemU7
Cn0gX19hdHRyaWJ1dGVfXyAoKHBhY2tlZCkpIHNtbF9hZ2xfZGF0YV90OwoKCnR5cGVkZWYgc3Ry
dWN0IHsKICBzbWxfYWdsX2RhdGFfdCBkYXRhWzldOwp9IF9fYXR0cmlidXRlX18gKChwYWNrZWQp
KSBzbWxfYWdsaV90OwoKCnR5cGVkZWYgc3RydWN0IHsKICBzbWxfYWdsaV90IHNtbF9hZ2xpOwp9
IF9fYXR0cmlidXRlX18gKChwYWNrZWQpKSBkc2lfdDsKCiNpZm5kZWYgX19HTlVDX18KI3ByYWdt
YSBwYWNrKCkKI2VuZGlmCgoKdHlwZWRlZiBzdHJ1Y3QgewogIGludCBhOwogIGRzaV90IGRzaV9w
YWNrOwp9IGR2ZF9wcml2X3Q7CgoKCmludApkdmRfcmVhZF9zZWN0b3IoZHZkX3ByaXZfdCAqZCx1
bnNpZ25lZCBjaGFyKiBkYXRhKQp7CiAgICBpbnQgaSxza2lwPTA7CiAgICAKICAgIGZvciAoaT0w
OyBpIDwgOTsgaSsrKQoJaWYgKChza2lwPWQtPmRzaV9wYWNrLnNtbF9hZ2xpLmRhdGFbaV0uYWRk
cmVzcykgIT0gMCkKCSAgICBicmVhazsKCiAgICByZXR1cm4gc2tpcDsKfQoKCm1haW4oKQp7CiAg
ICBzdGF0aWMgZHZkX3ByaXZfdCBkdmRfcHJpdjsKICAgIGR2ZF9yZWFkX3NlY3RvcigmZHZkX3By
aXYsIDApOwp9Cg==


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]