Skip to content

Add -D_FORTIFY_SOURCE=2 for fixing hardening-check #149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions backends/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,10 @@ if(WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qstd=c++17")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb3 -DDEBUG ")
elseif(UNIX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \
-Wall -Wextra -Winit-self -Wuninitialized -Wmissing-declarations \
-fdiagnostics-color=auto -O3 \
")
set(SDL_FLAGS "-fstack-protector -fstack-protector-all -fpic -fPIC -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -fno-strict-overflow -fno-delete-null-pointer-checks")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we reformat the flags like this to make them readable. Also do we not need -O3 ?

    set(CMAKE_C_FLAGS "                                                        \
        ${CMAKE_C_FLAGS}                                                       \
       -Wall                                                                   \
       -Wextra                                                                 \
       -Winit-self                                                             \
       -Wuninitialized                                                         \
       -Wmissing-declarations                                                  \
       -fdiagnostics-color=auto -O3                                            \
    ")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qstd=c++17")
    set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb3 -DDEBUG ")
elseif(UNIX)
    set(SDL_FLAGS "                                                            \
        -fstack-protector                                                      \
        -fstack-protector-all                                                  \
        -fpic                                                                  \
        -fPIC                                                                  \
        -D_FORTIFY_SOURCE=2                                                    \
        -Wformat                                                               \
        -Wformat-security                                                      \
        -fno-strict-overflow                                                   \
        -fno-delete-null-pointer-checks                                        \
        "
    )
    set(CMAKE_C_FLAGS "                                                        \
        ${CMAKE_C_FLAGS}                                                       \
        ${SDL_FLAGS}                                                           \
        -Wall                                                                  \
        -Wextra                                                                \
        -Winit-self                                                            \
        -Wuninitialized                                                        \
        -Wmissing-declarations                                                 \
        -fdiagnostics-color=auto                                               \
        -O3                                                                    \
        "
    )
    set(CMAKE_C_FLAGS_DEBUG "                                                  \
        ${CMAKE_C_FLAGS_DEBUG}                                                 \
         ${SDL_FLAGS}                                                          \
        -Wall                                                                  \
        -Wextra                                                                \
        -Winit-self                                                            \
        -Wuninitialized                                                        \
        -Wmissing-declarations                                                 \
        -fdiagnostics-color=auto                                               \
        -O0                                                                    \
        -ggdb3                                                                 \
        -DDEBUG                                                                \
        "
    )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This style of formatting makes a lot spaces in commands. You can see all calls to compilers if use make -j4 VERBOSE=1.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There will be a lot of spaces.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would propose to use add_compile_options()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, Then never mind.

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SDL_FLAGS} -Wall -Wextra -Winit-self -Wuninitialized -Wmissing-declarations -fdiagnostics-color=auto")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb3 -DDEBUG ")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -fsycl")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SDL_FLAGS} -std=c++17 -fsycl")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-O3 needs to be added?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-O3 is part of CMAKE_CXX_FLAGS_RELEASE.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course.

else()
message(FATAL_ERROR "Unsupported system.")
endif()
Expand Down