Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2011-09

alignment warnings

7 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Henry Vermaak

Hi list

Thinking more about the alignment problems on arm and elsewhere, I was wondering how hard it would be to implement something like gcc's -Wcast-align. Here's a description from the man page:

Warn whenever a pointer is cast such that the required alignment of the target is increased. For example, warn if a "char *" is cast to an "int *" on machines where integers can only be accessed at two- or four-byte boundaries.

This would really help to catch problematic code before things get out of hand and you have to wait for segfault/sigbus before you know where the problems are.

Henry

Reply by email

Martin
to Henry Vermaak
Henry Vermaak wrote 10 lines
Hi list Thinking more about the alignment problems on arm and elsewhere, I was wondering how hard it would be to implement something like gcc's -Wcast-align. Here's a description from the man page: Warn whenever a pointer is cast such that the required alignment of the target is increased. For example, warn if a "char *" is cast to an "int *" on machines where integers can only be accessed at two- or four-byte boundaries.

Why limit it to "on machines where ... can only be accessed at ... boundaries".
If code is written for multiply platforms, then the implementor may be on a machine where the cast is allowed, and needs no warning, but soon as the code is compiled on a different architecture, the warnings come up. It would be good, if one could also enable warnings for code, that may have issues on other platforms

Reply by email

Henry Vermaak
to Martin
Martin wrote 19 lines
On 30/09/2011 10:44, Henry Vermaak wrote: > Hi list > > Thinking more about the alignment problems on arm and elsewhere, I was > wondering how hard it would be to implement something like gcc's > -Wcast-align. Here's a description from the man page: > > Warn whenever a pointer is cast such that the required alignment of > the target is increased. For example, warn if a "char *" is cast to an > "int *" on machines where integers can only be accessed at two- or > four-byte boundaries. Why limit it to "on machines where ... can only be accessed at ... boundaries". If code is written for multiply platforms, then the implementor may be on a machine where the cast is allowed, and needs no warning, but soon as the code is compiled on a different architecture, the warnings come up. It would be good, if one could also enable warnings for code, that may have issues on other platforms

Because you may be writing code that's specific to a platform? I guess you can have another option that will warn on all machines.

Henry

Reply by email

Mark Morgan Lloyd
to Henry Vermaak
Henry Vermaak wrote 24 lines
On 30/09/11 10:52, Martin wrote: > On 30/09/2011 10:44, Henry Vermaak wrote: >> Hi list >> >> Thinking more about the alignment problems on arm and elsewhere, I was >> wondering how hard it would be to implement something like gcc's >> -Wcast-align. Here's a description from the man page: >> >> Warn whenever a pointer is cast such that the required alignment of >> the target is increased. For example, warn if a "char *" is cast to an >> "int *" on machines where integers can only be accessed at two- or >> four-byte boundaries. > > Why limit it to "on machines where ... can only be accessed at ... > boundaries". > If code is written for multiply platforms, then the implementor may be > on a machine where the cast is allowed, and needs no warning, but soon > as the code is compiled on a different architecture, the warnings come > up. > It would be good, if one could also enable warnings for code, that may > have issues on other platforms Because you may be writing code that's specific to a platform? I guess you can have another option that will warn on all machines.

I think we need to take into account the particular case of ARM, where some implementations are stricter than others but there's no indication/test in the ABI or loader.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Florian Klämpfl
to Henry Vermaak: Hi list Thinking more about the alignment problems on arm and elsewhere, I was wondering…
Henry Vermaak wrote 10 lines
Hi list Thinking more about the alignment problems on arm and elsewhere, I was wondering how hard it would be to implement something like gcc's -Wcast-align. Here's a description from the man page: Warn whenever a pointer is cast such that the required alignment of the target is increased. For example, warn if a "char *" is cast to an "int *" on machines where integers can only be accessed at two- or four-byte boundaries.

The problem with such warnings is that one cannot get easily rid of them. Maybe a hint would be more suitable.

Show quoted text 10 lines
This would really help to catch problematic code before things get out of hand and you have to wait for segfault/sigbus before you know where the problems are. Henry _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email

Henry Vermaak
to Florian Klämpfl
Florian Klämpfl wrote 15 lines
Am 30.09.2011 11:44, schrieb Henry Vermaak: > > Hi list > > Thinking more about the alignment problems on arm and elsewhere, I was > wondering how hard it would be to implement something like gcc's > -Wcast-align. Here's a description from the man page: > > Warn whenever a pointer is cast such that the required alignment of the > target is increased. For example, warn if a "char *" is cast to an "int > *" on machines where integers can only be accessed at two- or four-byte > boundaries. The problem with such warnings is that one cannot get easily rid of them. Maybe a hint would be more suitable.

Yes, probably, you would want to switch this off most of the time, I guess. Is this hard to implement?

Henry

Reply by email

Ludo Brands
to Henry Vermaak
Show quoted text 19 lines
>> Thinking more about the alignment problems on arm and elsewhere, I >> was wondering how hard it would be to implement something like gcc's >> -Wcast-align. Here's a description from the man page: >> >> Warn whenever a pointer is cast such that the required alignment of >> the target is increased. For example, warn if a "char *" is cast to >> an "int *" on machines where integers can only be accessed at two- or >> four-byte boundaries. > > The problem with such warnings is that one cannot get easily rid of > them. Maybe a hint would be more suitable. Yes, probably, you would want to switch this off most of the time, I guess. Is this hard to implement?

One of the difficulties is probably pointers to packed records. Depending on the members of the record the alignment requirement can be 1,2,4 or more bytes. OS API's contain a lot of these.
Packed records are an aligment "hazard" on their own. They also could use a warning/hint when members are not on a correctly aligned offset.

Ludo

Reply by email