intel/libipt

2.1: LTO exposes `[-Werror=maybe-uninitialized]` warnings

kloczek opened this issue · 4 comments

Looks like LTO exposes in 2.1 ne warnings

[tkloczko@pers-jacek x86_64-redhat-linux-gnu]$ make -k >/dev/null
In function ‘get_offset_null’,
    inlined from ‘main’ at /home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/test/src/ptunit-encoder.c:232:2:
/home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/test/src/ptunit-encoder.c:144:19: error: ‘encoder’ may be used uninitialized [-Werror=maybe-uninitialized]
  144 |         errcode = pt_enc_get_offset(&encoder, NULL);
      |                   ^
/home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/src/pt_encoder.c: In function ‘main’:
/home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/src/pt_encoder.c:105:5: note: by argument 1 of type ‘const struct pt_encoder *’ to ‘pt_enc_get_offset’ declared here
  105 | int pt_enc_get_offset(const struct pt_encoder *encoder, uint64_t *offset)
      |     ^
/home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/test/src/ptunit-encoder.c:137:27: note: ‘encoder’ declared here
  137 |         struct pt_encoder encoder;
      |                           ^
lto1: all warnings being treated as errors
lto-wrapper: fatal error: /usr/bin/gcc returned 1 exit status
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
make[2]: *** [libipt/CMakeFiles/ptunit-encoder.dir/build.make:133: bin/ptunit-encoder] Error 1
make[2]: Target 'libipt/CMakeFiles/ptunit-encoder.dir/build' not remade because of errors.
make[1]: *** [CMakeFiles/Makefile2:707: libipt/CMakeFiles/ptunit-encoder.dir/all] Error 2
In function ‘get_offset_null’,
    inlined from ‘main’ at /home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/test/src/ptunit-packet_decoder.c:266:2:
/home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/test/src/ptunit-packet_decoder.c:164:19: error: ‘decoder’ may be used uninitialized [-Werror=maybe-uninitialized]
  164 |         errcode = pt_pkt_get_offset(&decoder, NULL);
      |                   ^
/home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/src/pt_packet_decoder.c: In function ‘main’:
/home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/src/pt_packet_decoder.c:171:5: note: by argument 1 of type ‘const struct pt_packet_decoder *’ to ‘pt_pkt_get_offset’ declared here
  171 | int pt_pkt_get_offset(const struct pt_packet_decoder *decoder, uint64_t *offset)
      |     ^
/home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/test/src/ptunit-packet_decoder.c:157:34: note: ‘decoder’ declared here
  157 |         struct pt_packet_decoder decoder;
      |                                  ^
In function ‘get_sync_offset_null’,
    inlined from ‘main’ at /home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/test/src/ptunit-packet_decoder.c:269:2:
/home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/test/src/ptunit-packet_decoder.c:205:19: error: ‘decoder’ may be used uninitialized [-Werror=maybe-uninitialized]
  205 |         errcode = pt_pkt_get_sync_offset(&decoder, NULL);
      |                   ^
/home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/src/pt_packet_decoder.c: In function ‘main’:
/home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/src/pt_packet_decoder.c:188:5: note: by argument 1 of type ‘const struct pt_packet_decoder *’ to ‘pt_pkt_get_sync_offset’ declared here
  188 | int pt_pkt_get_sync_offset(const struct pt_packet_decoder *decoder,
      |     ^
/home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/test/src/ptunit-packet_decoder.c:198:34: note: ‘decoder’ declared here
  198 |         struct pt_packet_decoder decoder;
      |                                  ^
lto1: all warnings being treated as errors
lto-wrapper: fatal error: /usr/bin/gcc returned 1 exit status
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
make[2]: *** [libipt/CMakeFiles/ptunit-packet_decoder.dir/build.make:261: bin/ptunit-packet_decoder] Error 1
make[2]: Target 'libipt/CMakeFiles/ptunit-packet_decoder.dir/build' not remade because of errors.
make[1]: *** [CMakeFiles/Makefile2:733: libipt/CMakeFiles/ptunit-packet_decoder.dir/all] Error 2
In function ‘pt_qry_get_offset’,
    inlined from ‘pt_insn_get_offset’ at /home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/src/pt_insn_decoder.c:381:9,
    inlined from ‘get_offset_null’ at /home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/test/src/ptunit-insn_decoder.c:164:12,
    inlined from ‘main’ at /home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/test/src/ptunit-insn_decoder.c:336:2:
/home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/src/pt_query_decoder.c:380:16: error: ‘decoder’ may be used uninitialized [-Werror=maybe-uninitialized]
  380 |         return pt_evt_get_offset(&decoder->evdec, offset);
      |                ^
/home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/src/pt_event_decoder.c: In function ‘main’:
/home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/src/pt_event_decoder.c:1541:5: note: by argument 1 of type ‘const struct pt_event_decoder *’ to ‘pt_evt_get_offset’ declared here
 1541 | int pt_evt_get_offset(const struct pt_event_decoder *decoder, uint64_t *offset)
      |     ^
/home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/test/src/ptunit-insn_decoder.c:157:32: note: ‘decoder’ declared here
  157 |         struct pt_insn_decoder decoder;
      |                                ^
In function ‘pt_evt_get_sync_offset’,
    inlined from ‘pt_qry_get_sync_offset’ at /home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/src/pt_query_decoder.c:389:9,
    inlined from ‘pt_insn_get_sync_offset’ at /home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/src/pt_insn_decoder.c:390:9,
    inlined from ‘get_sync_offset_null’ at /home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/test/src/ptunit-insn_decoder.c:190:12,
    inlined from ‘main’ at /home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/test/src/ptunit-insn_decoder.c:338:2:
/home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/src/pt_event_decoder.c:1564:16: error: ‘decoder’ may be used uninitialized [-Werror=maybe-uninitialized]
 1564 |         return pt_pkt_get_sync_offset(&decoder->pacdec, offset);
      |                ^
/home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/src/pt_packet_decoder.c: In function ‘main’:
/home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/src/pt_packet_decoder.c:188:5: note: by argument 1 of type ‘const struct pt_packet_decoder *’ to ‘pt_pkt_get_sync_offset’ declared here
  188 | int pt_pkt_get_sync_offset(const struct pt_packet_decoder *decoder,
      |     ^
/home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/test/src/ptunit-insn_decoder.c:183:32: note: ‘decoder’ declared here
  183 |         struct pt_insn_decoder decoder;
      |                                ^
lto1: all warnings being treated as errors
lto-wrapper: fatal error: /usr/bin/gcc returned 1 exit status
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
make[2]: *** [libipt/CMakeFiles/ptunit-insn_decoder.dir/build.make:517: bin/ptunit-insn_decoder] Error 1
make[2]: Target 'libipt/CMakeFiles/ptunit-insn_decoder.dir/build' not remade because of errors.
make[1]: *** [CMakeFiles/Makefile2:759: libipt/CMakeFiles/ptunit-insn_decoder.dir/all] Error 2
In function ‘pt_qry_get_offset’,
    inlined from ‘get_offset_null’ at /home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/test/src/ptunit-block_decoder.c:164:12,
    inlined from ‘main’ at /home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/test/src/ptunit-block_decoder.c:336:2:
/home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/src/pt_query_decoder.c:380:16: error: ‘decoder’ may be used uninitialized [-Werror=maybe-uninitialized]
  380 |         return pt_evt_get_offset(&decoder->evdec, offset);
      |                ^
/home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/src/pt_event_decoder.c: In function ‘main’:
/home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/src/pt_event_decoder.c:1541:5: note: by argument 1 of type ‘const struct pt_event_decoder *’ to ‘pt_evt_get_offset’ declared here
 1541 | int pt_evt_get_offset(const struct pt_event_decoder *decoder, uint64_t *offset)
      |     ^
/home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/test/src/ptunit-block_decoder.c:157:33: note: ‘decoder’ declared here
  157 |         struct pt_block_decoder decoder;
      |                                 ^
In function ‘pt_evt_get_sync_offset’,
    inlined from ‘pt_qry_get_sync_offset’ at /home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/src/pt_query_decoder.c:389:9,
    inlined from ‘get_sync_offset_null’ at /home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/test/src/ptunit-block_decoder.c:190:12,
    inlined from ‘main’ at /home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/test/src/ptunit-block_decoder.c:338:2:
/home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/src/pt_event_decoder.c:1564:16: error: ‘decoder’ may be used uninitialized [-Werror=maybe-uninitialized]
 1564 |         return pt_pkt_get_sync_offset(&decoder->pacdec, offset);
      |                ^
/home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/src/pt_packet_decoder.c: In function ‘main’:
/home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/src/pt_packet_decoder.c:188:5: note: by argument 1 of type ‘const struct pt_packet_decoder *’ to ‘pt_pkt_get_sync_offset’ declared here
  188 | int pt_pkt_get_sync_offset(const struct pt_packet_decoder *decoder,
      |     ^
/home/tkloczko/rpmbuild/BUILD/libipt-2.1/libipt/test/src/ptunit-block_decoder.c:183:33: note: ‘decoder’ declared here
  183 |         struct pt_block_decoder decoder;
      |                                 ^
lto1: all warnings being treated as errors
lto-wrapper: fatal error: /usr/bin/gcc returned 1 exit status
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
make[2]: *** [libipt/CMakeFiles/ptunit-block_decoder.dir/build.make:517: bin/ptunit-block_decoder] Error 1
make[2]: Target 'libipt/CMakeFiles/ptunit-block_decoder.dir/build' not remade because of errors.
make[1]: *** [CMakeFiles/Makefile2:785: libipt/CMakeFiles/ptunit-block_decoder.dir/all] Error 2
make[1]: Target 'all' not remade because of errors.
make: *** [Makefile:149: all] Error 2
make: Target 'default_target' not remade because of errors.

Thanks for reporting this. Could you share how you configured cmake?

From my spec file

%cmake \
        -D DEVBUILD=ON \
        -D MAN=ON \
        -D PTUNIT=ON \
        %{nil}

Nevertheless in this case LTO options are passed over $CXXFLAGS and $LDFLAGS env variables.

I tried adding -flto and found an issue in pttc, but no further issues on ubuntu 22.04 with GCC 11.4.0. What system and compiler are you using?

I'm using gcc 13.2.1.