Skip to content

Instantly share code, notes, and snippets.

@gszr
Created April 5, 2024 14:33
Show Gist options
  • Save gszr/05b43652556e0a1f8dd570806a8e914e to your computer and use it in GitHub Desktop.
Save gszr/05b43652556e0a1f8dd570806a8e914e to your computer and use it in GitHub Desktop.
lua-protobuf issue

Before

(kong-dev) kong $ luarocks install lua-protobuf 0.5.0 CC=/usr/bin/gcc CFLAGS="-O2 -fPIC -fstrict-aliasing -Wstrict-aliasing=2"              master
Installing https://luarocks.org/lua-protobuf-0.5.0-1.src.rock

lua-protobuf 0.5.0-1 depends on lua >= 5.1 (5.1-1 provided by VM: success)
/usr/bin/gcc -O2 -fPIC -fstrict-aliasing -Wstrict-aliasing=2 -I/home/gs/code/work/kong/bazel-bin/build/kong-dev/openresty/luajit/include/luajit-2.1 -c pb.c -o pb.o
In file included from pb.c:11:
pb.h: In function ‘pb_nexttype’:
pb.h:1206:58: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
 1206 |         while (pb_nextentry(&S->types, (const pb_Entry**)&e))
      |                                                          ^~
pb.h: In function ‘pb_nextfield’:
pb.h:1219:63: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
 1219 |         while (pb_nextentry(&t->field_tags, (const pb_Entry**)&e))
      |                                                               ^~
pb.h: In function ‘pbL_EnumDescriptorProto’:
pb.h:1365:41: warning: dereferencing type-punned pointer might break strict-aliasing rules [-Wstrict-aliasing]
 1365 | #define pbL_add(A)    (pbL_grow((void**)&(A),sizeof(*(A)))==PB_OK ?\
      |                                         ^~~~
pb.h:1353:31: note: in definition of macro ‘pbC’
 1353 | #define pbC(e)  do { int r = (e); if (r != PB_OK) return r; } while (0)
      |                               ^
pb.h:1522:49: note: in expansion of macro ‘pbL_add’
 1522 |             pbC(pbL_EnumValueDescriptorProto(L, pbL_add(info->value))); break;
      |                                                 ^~~~~~~
pb.h: In function ‘pbL_OneofDescriptorProto’:
pb.h:1365:41: warning: dereferencing type-punned pointer might break strict-aliasing rules [-Wstrict-aliasing]
 1365 | #define pbL_add(A)    (pbL_grow((void**)&(A),sizeof(*(A)))==PB_OK ?\
      |                                         ^~~~
pb.h:1353:31: note: in definition of macro ‘pbC’
 1353 | #define pbC(e)  do { int r = (e); if (r != PB_OK) return r; } while (0)
      |                               ^
pb.h:1552:34: note: in expansion of macro ‘pbL_add’
 1552 |             pbC(pbL_readbytes(L, pbL_add(info->oneof_decl))); break;
      |                                  ^~~~~~~
pb.h: In function ‘pbL_DescriptorProto’:
pb.h:1365:41: warning: dereferencing type-punned pointer might break strict-aliasing rules [-Wstrict-aliasing]
 1365 | #define pbL_add(A)    (pbL_grow((void**)&(A),sizeof(*(A)))==PB_OK ?\
      |                                         ^~~~
pb.h:1353:31: note: in definition of macro ‘pbC’
 1353 | #define pbC(e)  do { int r = (e); if (r != PB_OK) return r; } while (0)
      |                               ^
pb.h:1569:45: note: in expansion of macro ‘pbL_add’
 1569 |             pbC(pbL_FieldDescriptorProto(L, pbL_add(info->field))); break;
      |                                             ^~~~~~~
pb.h:1365:41: warning: dereferencing type-punned pointer might break strict-aliasing rules [-Wstrict-aliasing]
 1365 | #define pbL_add(A)    (pbL_grow((void**)&(A),sizeof(*(A)))==PB_OK ?\
      |                                         ^~~~
pb.h:1353:31: note: in definition of macro ‘pbC’
 1353 | #define pbC(e)  do { int r = (e); if (r != PB_OK) return r; } while (0)
      |                               ^
pb.h:1571:45: note: in expansion of macro ‘pbL_add’
 1571 |             pbC(pbL_FieldDescriptorProto(L, pbL_add(info->extension))); break;
      |                                             ^~~~~~~
pb.h:1365:41: warning: dereferencing type-punned pointer might break strict-aliasing rules [-Wstrict-aliasing]
 1365 | #define pbL_add(A)    (pbL_grow((void**)&(A),sizeof(*(A)))==PB_OK ?\
      |                                         ^~~~
pb.h:1353:31: note: in definition of macro ‘pbC’
 1353 | #define pbC(e)  do { int r = (e); if (r != PB_OK) return r; } while (0)
      |                               ^
pb.h:1573:40: note: in expansion of macro ‘pbL_add’
 1573 |             pbC(pbL_DescriptorProto(L, pbL_add(info->nested_type))); break;
      |                                        ^~~~~~~
pb.h:1365:41: warning: dereferencing type-punned pointer might break strict-aliasing rules [-Wstrict-aliasing]
 1365 | #define pbL_add(A)    (pbL_grow((void**)&(A),sizeof(*(A)))==PB_OK ?\
      |                                         ^~~~
pb.h:1353:31: note: in definition of macro ‘pbC’
 1353 | #define pbC(e)  do { int r = (e); if (r != PB_OK) return r; } while (0)
      |                               ^
pb.h:1575:44: note: in expansion of macro ‘pbL_add’
 1575 |             pbC(pbL_EnumDescriptorProto(L, pbL_add(info->enum_type))); break;
      |                                            ^~~~~~~
pb.h: In function ‘pbL_FileDescriptorProto’:
pb.h:1365:41: warning: dereferencing type-punned pointer might break strict-aliasing rules [-Wstrict-aliasing]
 1365 | #define pbL_add(A)    (pbL_grow((void**)&(A),sizeof(*(A)))==PB_OK ?\
      |                                         ^~~~
pb.h:1353:31: note: in definition of macro ‘pbC’
 1353 | #define pbC(e)  do { int r = (e); if (r != PB_OK) return r; } while (0)
      |                               ^
pb.h:1596:40: note: in expansion of macro ‘pbL_add’
 1596 |             pbC(pbL_DescriptorProto(L, pbL_add(info->message_type))); break;
      |                                        ^~~~~~~
pb.h:1365:41: warning: dereferencing type-punned pointer might break strict-aliasing rules [-Wstrict-aliasing]
 1365 | #define pbL_add(A)    (pbL_grow((void**)&(A),sizeof(*(A)))==PB_OK ?\
      |                                         ^~~~
pb.h:1353:31: note: in definition of macro ‘pbC’
 1353 | #define pbC(e)  do { int r = (e); if (r != PB_OK) return r; } while (0)
      |                               ^
pb.h:1598:44: note: in expansion of macro ‘pbL_add’
 1598 |             pbC(pbL_EnumDescriptorProto(L, pbL_add(info->enum_type))); break;
      |                                            ^~~~~~~
pb.h:1365:41: warning: dereferencing type-punned pointer might break strict-aliasing rules [-Wstrict-aliasing]
 1365 | #define pbL_add(A)    (pbL_grow((void**)&(A),sizeof(*(A)))==PB_OK ?\
      |                                         ^~~~
pb.h:1353:31: note: in definition of macro ‘pbC’
 1353 | #define pbC(e)  do { int r = (e); if (r != PB_OK) return r; } while (0)
      |                               ^
pb.h:1600:45: note: in expansion of macro ‘pbL_add’
 1600 |             pbC(pbL_FieldDescriptorProto(L, pbL_add(info->extension))); break;
      |                                             ^~~~~~~
gcc  -shared -o /tmp/luarocks_build-lua-protobuf-0.5.0-1-2510062/pb.so pb.o
lua-protobuf 0.5.0-1 is now installed in /home/gs/code/work/kong/bazel-bin/build/kong-dev (license: MIT)

After

(kong-dev) kong $ luarocks install lua-protobuf 0.5.1 CC=/usr/bin/gcc CFLAGS="-O2 -fPIC -fstrict-aliasing -Wstrict-aliasing=2"              master
Installing https://luarocks.org/lua-protobuf-0.5.1-1.src.rock

lua-protobuf 0.5.1-1 depends on lua >= 5.1 (5.1-1 provided by VM: success)
/usr/bin/gcc -O2 -fPIC -fstrict-aliasing -Wstrict-aliasing=2 -I/home/gs/code/work/kong/bazel-bin/build/kong-dev/openresty/luajit/include/luajit-2.1 -c pb.c -o pb.o
gcc  -shared -o /tmp/luarocks_build-lua-protobuf-0.5.1-1-2536339/pb.so pb.o
lua-protobuf 0.5.1-1 is now installed in /home/gs/code/work/kong/bazel-bin/build/kong-dev (license: MIT)

Notes

Strict aliasing-related warnings are gone and so is the segfault.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment