Pārlūkot izejas kodu

more binary size reduction .. 68kb server

Julius Pfrommer 10 gadi atpakaļ
vecāks
revīzija
b7e565d658
2 mainītis faili ar 6 papildinājumiem un 4 dzēšanām
  1. 6 3
      CMakeLists.txt
  2. 0 1
      examples/networklayer_tcp.c

+ 6 - 3
CMakeLists.txt

@@ -25,8 +25,8 @@ add_definitions(-std=c99 -pipe -Wall -Wextra -Werror -Wformat
                 -Winit-self -Wuninitialized -Wno-deprecated -Wformat-security -ffunction-sections -fdata-sections)
     if(NOT "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
         add_definitions(-Wformat-nonliteral)
-        set (CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,--gc-sections")
-        set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections")
+        set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,--gc-sections")
+        set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections")
         set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
     else()
         add_definitions(-Wno-gnu-statement-expression)
@@ -35,8 +35,11 @@ add_definitions(-std=c99 -pipe -Wall -Wextra -Werror -Wformat
         set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s") # Strip binary
     endif()
 	if(NOT WIN32)
-	    add_definitions(-fstack-protector -fPIC -fvisibility=hidden)
+	    add_definitions(-fvisibility=hidden -fPIC)
 	endif()
+    # binary size reduction settings
+	add_definitions(-fno-stack-protector -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-math-errno -fmerge-all-constants -fno-ident)
+    set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,-z,norelro -Wl,--hash-style=gnu -Wl,--build-id=none")
 endif()
 
 # build the main library

+ 0 - 1
examples/networklayer_tcp.c

@@ -22,7 +22,6 @@
 # include <sys/select.h> 
 # include <netinet/in.h>
 # include <netinet/tcp.h>
-# include <sys/socketvar.h>
 # include <sys/ioctl.h>
 # include <netdb.h> //gethostbyname for the client
 # include <unistd.h> // read, write, close