From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Wilson Kwan" To: , "Lewin A.R.W. Edwards" Subject: Re: [ECOS] Yet another ARM alignment question Date: Wed, 25 Apr 2001 08:11:00 -0000 Message-id: <001a01c0cd99$b4c40710$0b02a8c0@obiwan> X-SW-Source: 2001-04/msg00402.html Content-type: multipart/mixed; boundary="----------=_1583532887-474-22" This is a multi-part message in MIME format... ------------=_1583532887-474-22 Content-length: 1903 Sorry, forgot to attach the code snippets. > Hi Lewin, > > > Hello Wilson, > > > > >My question is has anyone solved the word and dword alignment problems on > > >ARM? Is is any combination of gcc compiler options that will overcome > this > > >limitation albeit at a performance cost. What about an alignment trap > > > > If you specify -fpack-struct on the gcc command line, gcc will not align > > data items in structures and will generate multiple ldrh/ldrb/strh/strb > > instructions to access the misaligned data items in those structures; is > > that what you're asking? The performance cost of doing this globally is > > _high_ and it's best avoided! > > I tried -fpack-struct to no effect. I believe that it may be a broken > option. I can get code to run properly if I use __attribute__ ((packed)). My > problem is that we have so much legacy code that it is not feasible to go > through all of it and add this attribute at this time. I'm running > arm-elf-gcc version 2.95.2 on Win NT 2000. I'm willing to take the > performance hit for now and will fix the general problem when I have more > time. > > > > > Is this a theoretical question or do you have an actual problem? (Can you > > post a little sample code along with a description of the symptom?) I > can't > > see where it would be an issue except in certain structures (e.g. my > > problem I had a while back generating structs to reflect various FAT > > structures). gcc will normally handle pointer arithmetic and dereferencing > > for you without difficulty. > > I've attached a test piece of code that exhibits the problem. I'm sure many > have encountered this before. The makefile uses the -fpack-struct option but > doesn't seem to fix the problem. Defining PACKED and recompiling does. Do > you know if there was a patch for gcc to fix this on Win NT? > > Thanks again Lewin. As always you're a great help. > > Wilson > > ------------=_1583532887-474-22 Content-Type: text/x-makefile; charset=us-ascii; name="Makefile" Content-Disposition: inline; filename="Makefile" Content-Transfer-Encoding: base64 Content-Length: 1151 UEtHX0lOU1RBTExfRElSID0gLy9kL3B1cnBsZS9lY29zL3RhcmdldHMvNzIx MV9pbnN0Y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_1583532887-474-22 Content-Type: text/x-c; charset=us-ascii; name="test3.c" Content-Disposition: inline; filename="test3.c" Content-Transfer-Encoding: base64 Content-Length: 2884 I2luY2x1ZGUgPGN5Zy9rZXJuZWwva2FwaS5oPgojaW5jbHVkZSA8Y3lnL2lu ZnJhL2RpYWcuaD4KI2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRs aWIuaD4KCiNpZmRlZiAgUEFDS0VECgojZGVmaW5lIFBBQ0sgICAgX19hdHRy aWJ1dGVfXyAoKHBhY2tlZCkpCgojZWxzZQoKI2RlZmluZSBQQUNLCgojZW5k aWYKCnR5cGVkZWYgc3RydWN0IHRhZ1JlY3RUeXBlIHsKICAgICAgICB1bnNp Z25lZCBzaG9ydCBsZWZ0OwogICAgICAgIHVuc2lnbmVkIHNob3J0IHRvcDsK ICAgICAgICB1bnNpZ25lZCBzaG9ydCByaWdodDsKICAgICAgICB1bnNpZ25l ZCBzaG9ydCBib3R0b207CiAgICAgICAgfSBQQUNLIFJlY3RUeXBlOwoKdHlw ZWRlZiBzdHJ1Y3QgdGFnV2luVHlwZSB7CiAgICAgICAgY2hhciAgICAgICAg ICAgICAgICAgICByZXNlcnZlZDsKICAgICAgICBSZWN0VHlwZSAgICAgICAg ICAgICAgIGNCb3VuZHM7CiAgICAgICAgdm9pZCAqICAgICAgICAgICAgICAg ICBkYXRhMTsKICAgICAgICBsb25nICAgICAgICAgICAgICAgICAgIGxkYXRh OwogICAgICAgIHN0cnVjdCB0YWdXaW5UeXBlICogICAgbmV4dDsKICAgICAg ICB9IFBBQ0sgV2luVHlwZTsKCgppbnQgbWFpbiAoCiAgIGludCAgIGFyZ2Ms CiAgIGNoYXIgKmFyZ3ZbXSkKICAgewogICBjaGFyICAgICAgIGJ1ZmZlciBb NjRdOwogICBXaW5UeXBlICAgKnd3d1B0cjsKICAgaW50ICAgICAgICBjb3Vu dDsKCiAgIGZvciAoY291bnQgPSAwOyBjb3VudCA8IDY0OyBjb3VudCsrKQog ICAgICB7CiAgICAgICooYnVmZmVyICsgY291bnQpID0gKGNoYXIpIChjb3Vu dCAlIDE2KTsKICAgICAgfSAvLyBlbmQgZm9yCgogICBkaWFnX3ByaW50ZiAo Ik1lbW9yeSBjb250ZW50c1xuIik7CiAgIGRpYWdfcHJpbnRmICgiPT09PT09 PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09 XG4iKTsKICAgZm9yIChjb3VudCA9IDA7IGNvdW50IDwgNjQ7IGNvdW50Kysp CiAgICAgIHsKICAgICAgdW5zaWduZWQgY2hhciAgIGJ5dGU7CgogICAgICBi eXRlID0gKihidWZmZXIgKyBjb3VudCk7CgogICAgICBkaWFnX3ByaW50ZiAo IiUwMnggIiwgYnl0ZSk7CgogICAgICBpZiAoIChjb3VudCArIDEpICUgMTYg PT0gMCkKICAgICAgICAgewogICAgICAgICBkaWFnX3ByaW50ZiAoIlxuIik7 CiAgICAgICAgIH0gLy8gZW5kaWYKICAgICAgfSAvLyBlbmQgZm9yCgogICBk aWFnX3ByaW50ZiAoIlxuXG5TaXplb2YgV2luVHlwZSA9ICVkXG5cbiIsIHNp emVvZiAoV2luVHlwZSkpOwoKICAgY291bnQgPSAwOwoKICAgY291bnQgKys7 CiAgIGZvciAoY291bnQgPSAwOyBjb3VudCA8IDU7IGNvdW50KyspCiAgICAg IHsKICAgICAgd3d3UHRyID0gKFdpblR5cGUgKikgJmJ1ZmZlciBbY291bnRd OwogICAgICBkaWFnX3ByaW50ZiAoIldpblR5cGUucmVzZXJ2ZWQgICAgICAg ID0gJTAyeFxuIiAsIHd3d1B0ci0+cmVzZXJ2ZWQgICAgICAgKTsKICAgICAg ZGlhZ19wcmludGYgKCJXaW5UeXBlLmNCb3VuZHMubGVmdCAgICA9ICUwNHhc biIgLCB3d3dQdHItPmNCb3VuZHMubGVmdCAgICk7CiAgICAgIGRpYWdfcHJp bnRmICgiV2luVHlwZS5jQm91bmRzLnRvcCAgICAgPSAlMDR4XG4iICwgd3d3 UHRyLT5jQm91bmRzLnRvcCAgICApOwogICAgICBkaWFnX3ByaW50ZiAoIldp blR5cGUuY0JvdW5kcy5yaWdodCAgID0gJTA0eFxuIiAsIHd3d1B0ci0+Y0Jv dW5kcy5yaWdodCAgKTsKICAgICAgZGlhZ19wcmludGYgKCJXaW5UeXBlLmNC b3VuZHMuYm90dG9tICA9ICUwNHhcbiIgLCB3d3dQdHItPmNCb3VuZHMuYm90 dG9tICk7CiAgICAgIGRpYWdfcHJpbnRmICgiV2luVHlwZS5kYXRhMSAgICAg ICAgICAgPSAlMDhseFxuIiwgd3d3UHRyLT5kYXRhMSAgICAgICAgICApOwog ICAgICBkaWFnX3ByaW50ZiAoIldpblR5cGUubGRhdGEgICAgICAgICAgID0g JTA4bHhcbiIsIHd3d1B0ci0+bGRhdGEgICAgICAgICAgKTsKICAgICAgZGlh Z19wcmludGYgKCJXaW5UeXBlLm5leHQgICAgICAgICAgICA9ICUwOGx4XG4i LCB3d3dQdHItPm5leHQgICAgICAgICAgICk7CiAgICAgIGRpYWdfcHJpbnRm ICgiXG4iKTsKICAgICAgfSAvLyBlbmQgZm9yCgogICByZXR1cm4gMDsKICAg fSAvLyBtYWluCg== ------------=_1583532887-474-22--