Skip to content

Add compiler switches replace dangerous function with safer ones. - #5089

Merged
Dongbo Wang (daxian-dbw) merged 4 commits into
PowerShell:masterfrom
TravisEz13:strlenFixes
Oct 18, 2017
Merged

Dongbo Wang (daxian-dbw) merged 4 commits into
PowerShell:masterfrom
TravisEz13:strlenFixes

Conversation

@TravisEz13

@TravisEz13 Travis Plunk (TravisEz13) commented Oct 11, 2017 •

Copy link
Copy Markdown
Member

This should fix #4975

Comment thread src/libpsl-native/CMakeLists.txt Outdated
# Can't use add_compile_options with 2.8.11
set(CMAKE_BUILD_TYPE "Release")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Werror -fstack-protector-strong -fpie")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Werror -fstack-protector-strong -fpie -DFORTIFY_SOURCE=2")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Based on the documentation, FORTIFY_SOURCE=2 isn't enabled unless you also use -O2 optimizations

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Resolved.

Comment thread src/libpsl-native/CMakeLists.txt Outdated
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Werror -fstack-protector-strong -fpie -DFORTIFY_SOURCE=2 -O2")

if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,relro,-z,now")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Will CMAKE_SYSTEM_NAME ever be set to 'Windows'?
Can you please share some resources where I can find what each of those options is for?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This component isn't built for Windows. The Windows flags should go in ...\src\powershell-native\coreclr_defs.cmake.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This Windows section should be removed

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Removed the windows case.

The docs are here:
https://cmake.org/cmake/help/v3.4/variable/CMAKE_HOST_SYSTEM_NAME.html#variable:CMAKE_HOST_SYSTEM_NAME
and
https://cmake.org/cmake/help/v3.4/variable/CMAKE_SYSTEM_NAME.html

BTW, we use this when compiling for ARM, set(CMAKE_SYSTEM_NAME Linux).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Travis Plunk (@TravisEz13) Thanks. I'm actually interested in the options like -Wl,-z,relro,-z,now, and would like to know what they mean. I quickly search them bug didn't find anything very useful.

It will be great if you can provide some pointers. And better, put the link in CMakeLists.txt as comments.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What about the other aspect of my comment? Are there corresponding flags that we can or should use with MSBuild when compiling pwrshplugin.dll?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I have another work item to run the scan that would detect these type of issues. I just merged a change to the build to give me the data to run the scan. I should have it done Monday.

@TravisEz13

Copy link
Copy Markdown
Member Author

Dongbo Wang (@daxian-dbw) Can you update your review?

@daxian-dbw Dongbo Wang (daxian-dbw) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would be great if you add comments about some links that has information about the options used here, like -Wl,-z,relro,-z,now

@daxian-dbw
Dongbo Wang (daxian-dbw) merged commit db6aec0 into PowerShell:master Oct 18, 2017
@TravisEz13
Travis Plunk (TravisEz13) deleted the strlenFixes branch October 18, 2017 17:12
@TravisEz13

Copy link
Copy Markdown
Member Author

I'll likely be making more changes. I'll include the detail where the tools give me them.

Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
…werShell#5089)

* Add compiler switches replace the dangerous function with safer ones.
* Add -02 and make linker flags per platform
* add -O2 for arm and add -z,now
* remove windows linker flags
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove use for strlen from native code

4 participants