diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2024-01-24 12:25:23 +0000 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2024-02-08 12:14:40 +1030 |
commit | 3f8f9745c75b333515f399fc2908ede2ed8014e9 (patch) | |
tree | 8223dff7469157ecc5bf7895ad1969998ccff073 /binutils/config.in | |
parent | 16688387ed6d31dcc5c069953248e6dee9912262 (diff) | |
download | binutils-3f8f9745c75b333515f399fc2908ede2ed8014e9.zip binutils-3f8f9745c75b333515f399fc2908ede2ed8014e9.tar.gz binutils-3f8f9745c75b333515f399fc2908ede2ed8014e9.tar.bz2 |
PR 31283 windmc: Parse input correctly on big endian hosts
On big endian hosts (eg. s390x) the windmc tool fails to parse even
trivial files:
$ cat test.mc
;
$ ./binutils/windmc ./test.mc
In test.mc at line 1: parser: syntax error.
In test.mc at line 1: fatal: syntax error.
The tool starts by reading the input as Windows CP1252 and then
converting it internally into an array of UTF-16LE, which it then
processes as an array of unsigned short (typedef unichar).
There are lots of ways this is wrong, but in the specific case of big
endian machines the little endian pairs of bytes are byte-swapped.
For example, the ';' character in the input above is first converted
to UTF16-LE byte sequence { 0x3b, 0x00 }, which is then cast to
unsigned short. On a big endian machine the first unichar appears to
be 0x3b00. The lexer is unable to recognize this as the comment
character ((unichar)';') and so parsing fails.
The simple fix is to convert the input to UTF-16BE on big endian
machines (and do the reverse conversion when writing the output).
Fixes: https://sourceware.org/bugzilla/show_bug.cgi?id=31283
Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
Diffstat (limited to 'binutils/config.in')
-rw-r--r-- | binutils/config.in | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/binutils/config.in b/binutils/config.in index a9a9f71..ee148c7 100644 --- a/binutils/config.in +++ b/binutils/config.in @@ -7,6 +7,9 @@ #endif #define __CONFIG_H__ 1 +/* Define if building universal (internal helper macro) */ +#undef AC_APPLE_UNIVERSAL_BUILD + /* Should ar and ranlib use -D behavior by default? */ #undef DEFAULT_AR_DETERMINISTIC @@ -256,6 +259,18 @@ /* Version number of package */ #undef VERSION +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel). */ +#if defined AC_APPLE_UNIVERSAL_BUILD +# if defined __BIG_ENDIAN__ +# define WORDS_BIGENDIAN 1 +# endif +#else +# ifndef WORDS_BIGENDIAN +# undef WORDS_BIGENDIAN +# endif +#endif + /* Define to 1 if `lex' declares `yytext' as a `char *' by default, not a `char[]'. */ #undef YYTEXT_POINTER |