Skip to content

Commit

Permalink
Set default opt level to O3
Browse files Browse the repository at this point in the history
This patch sets the default opt level to O3 rather than Os meaning to
optimize strongly for speed instead of optimizing for size, this roughly
doubles the binary size from 100kb -> 190kb in my tests. But the
resulting binary performs 3-4x better.

On our target devices we have 90kb to spare and need every ounce of
performance we can get to keep babel networks from going unstable when
an individual router has many neighbors.

The new opt level causes some compiler warnings that where not
previously present, these are muted as they are warning of intended
behavior. Our fixed size target strings do not need to be null
terminated and we do intend to truncate longer strings if provided.
  • Loading branch information
jkilpatr committed Jun 28, 2023
1 parent d360465 commit 0bcc4c9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CDEBUGFLAGS = -O0 -g -Wall $(DEFINES) $(EXTRA_DEFINES)

DEFINES = $(PLATFORM_DEFINES)

CFLAGS = -Os -Wall $(DEFINES) $(EXTRA_DEFINES)
CFLAGS = -O3 -Wall $(DEFINES) $(EXTRA_DEFINES)

LDLIBS = -lrt -lm

Expand Down
4 changes: 4 additions & 0 deletions interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ add_interface(char *ifname, struct interface_conf *if_conf)
if(ifp == NULL)
return NULL;

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstringop-truncation"
strncpy(ifp->name, ifname, IF_NAMESIZE);
#pragma GCC diagnostic pop

ifp->conf = if_conf ? if_conf : default_interface_conf;
ifp->bucket_time = now.tv_sec;
ifp->bucket = BUCKET_TOKENS_MAX;
Expand Down
5 changes: 5 additions & 0 deletions net.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,12 @@ unix_server_socket(const char *path)

memset(&sun, 0, sizeof(sun));
sun.sun_family = AF_UNIX;

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstringop-truncation"
strncpy(sun.sun_path, path, sizeof(sun.sun_path));
#pragma GCC diagnostic pop

rc = bind(s, (struct sockaddr *)&sun, sizeof(sun));
if(rc < 0)
goto fail;
Expand Down

0 comments on commit 0bcc4c9

Please sign in to comment.