[tnozaki-elftoolchain] TNF local patch for libelf - miscellaneous lint(1) warning fix for libelf_convert.m4
Issue #279
wontfix
No description provided.
Comments (4)
-
reporter -
reporter WRITE_{HALF,WORD,WORD64} macro, uint{16,32,64}_t to byte array is rewrited as following:
#define WRITE_HALF(P,X) do { \ - uint16_t _t = (X); \ - unsigned char *const _p = (unsigned char *) (P); \ - unsigned const char *const _q = (unsigned char *) &_t; \ - _p[0] = _q[0]; \ - _p[1] = _q[1]; \ - (P) = _p + 2; \ + union { \ + uint16_t val; \ + uint8_t bytes[2]; \ + } _t; \ + unsigned char *const _p = (void *) (P); \ + _t.val = (X); \ + _p[0] = _t.bytes[0]; \ + _p[1] = _t.bytes[1]; \ + (P) = (void *)(_p + 2); \ } while (/*CONSTCOND*/0) #define WRITE_WORD(P,X) do { \ - uint32_t _t = (X); \ - unsigned char *const _p = (unsigned char *) (P); \ - unsigned const char *const _q = (unsigned char *) &_t; \ - _p[0] = _q[0]; \ - _p[1] = _q[1]; \ - _p[2] = _q[2]; \ - _p[3] = _q[3]; \ - (P) = _p + 4; \ + union { \ + uint32_t val; \ + uint8_t bytes[4]; \ + } _t; \ + unsigned char *const _p = (void *) (P); \ + _t.val = (X); \ + _p[0] = _t.bytes[0]; \ + _p[1] = _t.bytes[1]; \ + _p[2] = _t.bytes[2]; \ + _p[3] = _t.bytes[3]; \ + (P) = (void *)(_p + 4); \ } while (/*CONSTCOND*/0) #define WRITE_WORD64(P,X) do { \ - uint64_t _t = (X); \ - unsigned char *const _p = (unsigned char *) (P); \ - unsigned const char *const _q = (unsigned char *) &_t; \ - _p[0] = _q[0]; \ - _p[1] = _q[1]; \ - _p[2] = _q[2]; \ - _p[3] = _q[3]; \ - _p[4] = _q[4]; \ - _p[5] = _q[5]; \ - _p[6] = _q[6]; \ - _p[7] = _q[7]; \ - (P) = _p + 8; \ + union { \ + uint64_t val; \ + uint8_t bytes[8]; \ + } _t; \ + unsigned char *const _p = (void *) (P); \ + _t.val = (X); \ + _p[0] = _t.bytes[0]; \ + _p[1] = _t.bytes[1]; \ + _p[2] = _t.bytes[2]; \ + _p[3] = _t.bytes[3]; \ + _p[4] = _t.bytes[4]; \ + _p[5] = _t.bytes[5]; \ + _p[6] = _t.bytes[6]; \ + _p[7] = _t.bytes[7]; \ + (P) = (void *)(_p + 8); \ } while (/*CONSTCOND*/0)
i think original code is ok for strict aliasing rule/type panning.
is there any penalty of compiler optimization? or lint(1) is poor?
-
reporter - changed status to wontfix
i would like keep difference with original code, NAK.
-
reporter - changed title to [tnozaki-elftoolchain] TNF local patch for libelf - miscellaneous lint(1) warning fix for libelf_convert.m4
- Log in to comment
this part and -Wcast-qual warning issue are fixed elftoolchain r3009 https://sourceforge.net/p/elftoolchain/code/3009/
ticket 448 https://sourceforge.net/p/elftoolchain/tickets/448/