Skip to content

Commit

Permalink
Update transport-native-epoll compile flags
Browse files Browse the repository at this point in the history
- Move libraries to LIBS where they should be, avoiding need for
  -Wl,--no-as-needed.
- Use -O2 instead of -O3; there are no tight loops so -O3 just increases
  code size for no benefit.
- Add -pipe for faster compilation.
- Add -D_FORTIFY_SOURCE=2 and -Wl,-z,relro for security.
- Add -Wl,-z,now for security and to improve musl
  compatibility. musl does not implement __strdup and __strndup which
  old glibc aliases strdup and strndup to, but OpenJDK loads libraries
  with RTLD_LAZY, so this is not discovered until too late. See
  grpc/grpc-java#8751 (comment)
  for more information.
  • Loading branch information
Hello71 committed Apr 4, 2022
1 parent feeec99 commit 5362c58
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions transport-native-epoll/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@
<unix.common.lib.dir>${project.build.directory}/unix-common-lib</unix.common.lib.dir>
<unix.common.lib.unpacked.dir>${unix.common.lib.dir}/META-INF/native/lib</unix.common.lib.unpacked.dir>
<unix.common.include.unpacked.dir>${unix.common.lib.dir}/META-INF/native/include</unix.common.include.unpacked.dir>
<jni.compiler.args.cflags>CFLAGS=-O3 -Werror -fno-omit-frame-pointer -Wunused-variable -fvisibility=hidden -I${unix.common.include.unpacked.dir}</jni.compiler.args.cflags>
<jni.compiler.args.ldflags>LDFLAGS=-L${unix.common.lib.unpacked.dir} -Wl,--no-as-needed -lrt -ldl -Wl,--whole-archive -l${unix.common.lib.name} -Wl,--no-whole-archive</jni.compiler.args.ldflags>
<jni.compiler.args.cflags>CFLAGS=-O2 -pipe -Werror -fno-omit-frame-pointer -Wunused-variable -fvisibility=hidden -D_FORTIFY_SOURCE=2 -I${unix.common.include.unpacked.dir}</jni.compiler.args.cflags>
<jni.compiler.args.ldflags>LDFLAGS=-Wl,-z,relro -Wl,-z,now -L${unix.common.lib.unpacked.dir}</jni.compiler.args.ldflags>
<jni.compiler.args.libs>LIBS=-Wl,--whole-archive -l${unix.common.lib.name} -Wl,--no-whole-archive -ldl</jni.compiler.args.libs>
<nativeSourceDirectory>${project.basedir}/src/main/c</nativeSourceDirectory>
<skipTests>true</skipTests>
</properties>
Expand Down Expand Up @@ -154,6 +155,7 @@
<platform>.</platform>
<configureArgs>
<arg>${jni.compiler.args.ldflags}</arg>
<arg>${jni.compiler.args.libs}</arg>
<arg>${jni.compiler.args.cflags}</arg>
<configureArg>--libdir=${project.build.directory}/native-build/target/lib</configureArg>
</configureArgs>
Expand Down Expand Up @@ -303,6 +305,7 @@
<platform>.</platform>
<configureArgs>
<arg>${jni.compiler.args.ldflags}</arg>
<arg>${jni.compiler.args.libs}</arg>
<arg>${jni.compiler.args.cflags}</arg>
<configureArg>--libdir=${project.build.directory}/native-build/target/lib</configureArg>
<configureArg>--host=aarch64-linux-gnu</configureArg>
Expand Down

0 comments on commit 5362c58

Please sign in to comment.