Skip to content

iar: linker_script: Parse LD style INPUT specifications #90394

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
30 changes: 25 additions & 5 deletions cmake/linker/iar/config_file_script.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -580,9 +580,6 @@ function(section_to_string)

if(keep)
list(APPEND to_be_kept "block ${name_clean}_${idx}")
foreach(setting ${input})
list(APPEND to_be_kept "section ${setting}")
endforeach()
endif()
if(DEFINED symbols)
list(LENGTH symbols symbols_count)
Expand Down Expand Up @@ -712,8 +709,27 @@ function(section_to_string)
# message(FATAL_ERROR "How to handle this? lma=${lma} vma=${vma}")
# endif()

set(TEMP "${TEMP}${section_type} ${part}section ${setting}")
set_property(GLOBAL APPEND PROPERTY ILINK_CURRENT_SECTIONS "section ${setting}")

# Setting may have file-pattern or not.
# <file-pattern>(<section-patterns>... )
# <file-pattern> is [library.a:]file
# e.g. foo.a:bar.o(.data*)
if(setting MATCHES "^([^\\(]+)\\((.+)\\)$")
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldnt this be [^\\)]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not AFAIK. You want to match anything that is not opening parenthesis and stop when you hit one. This is usually what you mean. and I started doing the non-greedy ones out of habit.

But matching the last parenthesis is not bad anyways. Maybe I will just end up using the regexp you wrote for ld (which I started with, and foolishly thought I could improve).

what do you think about my addition of ^$, could this cause any issues? This is also just regexp habit from my side

I have a hard time seeing filenames/sections with : and ( being well defined. and in that case a more general escaping mechanism would be necessary anyways, and that would probably be much clearly expressed in code, and not a regexp.

Copy link
Contributor

Choose a reason for hiding this comment

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

I thought you wanted to match anything upto a closing ) Maybe we just have different greediness habbits ;)

set(file_pattern "${CMAKE_MATCH_1}")
set(section_pattern "${CMAKE_MATCH_2}")

# This contains library:object specification.
# This is translated from LD lib.a:obj.o to IARs obj.o(lib.a).
if(file_pattern MATCHES "^([^:]+):(.+)$")
set(file_pattern "${CMAKE_MATCH_2}(${CMAKE_MATCH_1})")
endif()
set(pattern "section ${section_pattern} object ${file_pattern}")
else()
set(pattern "section ${setting}")
endif()

set(TEMP "${TEMP}${section_type} ${part} ${pattern}")
set_property(GLOBAL APPEND PROPERTY ILINK_CURRENT_SECTIONS "${pattern}")
set(section_type "")

if("${setting}" STREQUAL "${last_input}")
Expand All @@ -722,6 +738,10 @@ function(section_to_string)
set(TEMP "${TEMP}, ")
endif()

if(keep)
list(APPEND to_be_kept "${pattern}")
endif()

# set(TEMP "${TEMP}\n *.o(${setting})")
endforeach()

Expand Down
Loading