Skip to content

Commit 0571348

Browse files
committed
llext: fix alignment of cold / detached sections
Cold sections within LLEXT modules should be page-size aligned to allow setting permission flags. They're never copied after being initially placed in DRAM, so alignment should happen already in ELF files. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
1 parent b9e6e14 commit 0571348

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

scripts/llext_link_helper.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ def parse_args():
2626
parser.add_argument('params', nargs='+', help='Additional linker parameters')
2727
parser.add_argument("-f", "--file", required=True, type=str,
2828
help='Object file name')
29+
parser.add_argument("-c", "--copy", required=True, type=str,
30+
help='Objcopy command')
31+
parser.add_argument("-o", "--output", required=True, type=str,
32+
help='Output file name')
2933
parser.add_argument("-t", "--text-addr", required=True, type=str,
3034
help='.text section address')
3135
parser.add_argument("-s", "--size-file", required=True, type=str,
@@ -148,11 +152,16 @@ def main():
148152
# we accept only the .coldrodata name for now.
149153

150154
dram_addr = 0
155+
first_dram_text = None
156+
first_dram_rodata = None
151157

152158
for section in executable:
153159
s_alignment = section.header['sh_addralign']
154160
s_name = section.name
155161

162+
if not first_dram_text:
163+
first_dram_text = s_name
164+
156165
dram_addr = align_up(dram_addr, s_alignment)
157166

158167
command.append(f'-Wl,--section-start={s_name}=0x{dram_addr:x}')
@@ -163,6 +172,9 @@ def main():
163172
s_alignment = section.header['sh_addralign']
164173
s_name = section.name
165174

175+
if not first_dram_rodata:
176+
first_dram_rodata = s_name
177+
166178
dram_addr = align_up(dram_addr, s_alignment)
167179

168180
command.append(f'-Wl,--section-start={s_name}=0x{dram_addr:x}')
@@ -196,9 +208,20 @@ def main():
196208

197209
start_addr += section.header['sh_size']
198210

211+
command.extend(['-o', f'{args.file}.tmp'])
199212
command.extend(args.params)
200213

201214
subprocess.run(command)
202215

216+
copy_command = [args.copy]
217+
218+
if first_dram_text:
219+
copy_command.extend(['--set-section-alignment', f'{first_dram_text}=4096'])
220+
if first_dram_rodata:
221+
copy_command.extend(['--set-section-alignment', f'{first_dram_rodata}=4096'])
222+
223+
copy_command.extend([f'{args.file}.tmp', f'{args.output}'])
224+
subprocess.run(copy_command)
225+
203226
if __name__ == "__main__":
204227
main()

zephyr/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ function(sof_llext_build module)
107107
POST_BUILD
108108
COMMAND ${PYTHON_EXECUTABLE} ${SOF_BASE}scripts/llext_link_helper.py -s ${size_file}
109109
--text-addr=${CONFIG_LIBRARY_BASE_ADDRESS}
110-
-f ${proc_in_file} ${CMAKE_C_COMPILER} --
111-
-o ${proc_out_file} ${EXTRA_LINKER_PARAMS}
112-
$<TARGET_OBJECTS:${module}_llext_lib>
110+
-c $<TARGET_PROPERTY:bintools,elfconvert_command>
111+
-f ${proc_in_file} -o ${proc_out_file} ${CMAKE_C_COMPILER} --
112+
${EXTRA_LINKER_PARAMS} $<TARGET_OBJECTS:${module}_llext_lib>
113113
)
114114

115115
add_llext_command(TARGET ${module}

0 commit comments

Comments
 (0)