Closed wdebruij closed 4 years ago
Thanks, Willem!
I am getting a gcc compilation error when I try this patch on a GCE Ubuntu 18.04 machine; gcc doesn't seem to like this unknown pragma thingy:
run_packet.c: In function âfind_tcp_timestampâ:
run_packet.c:408:32: error: unknown option after â#pragma GCC diagnosticâ kind [-Werror=pragmas]
#pragma GCC diagnostic ignored "-Waddress-of-packed-member"
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
<builtin>: recipe for target 'run_packet.o' failed
make: *** [run_packet.o] Error 1
ncardwell@nealtest6:~/packetdrill/gtests/net/packetdrill$ gcc --version
gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0
Is there a way to get older gcc compilers to ignore pragmas they don't understand?
If so, great. If not, the following hack might be one way to avoid this failure? Or at least it works on my Ubuntu 18.04 GCE machine:
diff --git a/gtests/net/packetdrill/run_packet.c b/gtests/net/packetdrill/run_packet.c
index 9c45d5a..4e94fe9 100644
--- a/gtests/net/packetdrill/run_packet.c
+++ b/gtests/net/packetdrill/run_packet.c
@@ -26,6 +26,7 @@
#include <arpa/inet.h>
#include <netinet/in.h>
+#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
@@ -405,9 +406,13 @@ static int find_tcp_timestamp(struct packet *packet, char **error)
option = tcp_options_next(&iter, error))
if (option->kind == TCPOPT_TIMESTAMP) {
packet->tcp_ts_val =
- (void *)&(option->data.time_stamp.val);
+ (void *)((char*)option +
+ offsetof(struct tcp_option,
+ data.time_stamp.val));
packet->tcp_ts_ecr =
- (void *)&(option->data.time_stamp.ecr);
+ (void *)((char*)option +
+ offsetof(struct tcp_option,
+ data.time_stamp.ecr));
}
return *error ? STATUS_ERR : STATUS_OK;
}
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.
. If the bot doesn't comment, it means it doesn't think anything has changed.
ℹ️ Googlers: Go here for more info.
Looks great. Thanks for fixing this!
Packetdrill needs to read and write possibly unaligned fields inside tpc headers. The accesses are safe, using unaligned_be32 helpers.
Recent versions of GCC start warning about the pointers to these fields, which causes build failure due to -Werror. Suppress the warning for this specific safe case.
" run_packet.c: In function ‘find_tcp_timestamp’: run_packet.c:408:13: error: taking address of packed member of ‘struct tcp_option’ may result in an unaligned pointer value [] 408 | (void )&(option->data.time_stamp.val); | ^
~~~~~~~~~ run_packet.c:410:13: error: taking address of packed member of ‘struct tcp_option’ may result in an unaligned pointer value [] 410 | (void )&(option->data.time_stamp.ecr); | ^~~~~~~~~~ "Signed-off-by: Willem de Bruijn willemb@google.com