Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linkage problems when adding S file to Linux kernel

After a previous question got answered: Adding a .S file to the linux kernel code I was able to add a .S file to the Linux kernel make files. However, my .S file includes several sections that replace functions that were written in C. I commented out these functions, and declared the replacement functions as globals, but when I try to link the kernel (using make) I get the following error:

arch/x86/kernel/vmlinux.lds:XXX: non constant or forward reference address expression for section .YYY

The original functions that I replaced were declared using: __attribute__ ((unused, __section__("YYY"))) notrace

The asm sections are declared using:

.text
.globl YYY

I also tried adding:

.type YYY,@function

I probably missed some declaration somewhere, but I'm not sure where to look.

Any ideas?

like image 916
Yoav Weiss Avatar asked Jun 27 '26 17:06

Yoav Weiss


2 Answers

If you want to place assembly functions into section YYY, rather than .text, you need to replace

.text

with

.section YYY,"ax"
like image 140
Matthew Slattery Avatar answered Jun 30 '26 09:06

Matthew Slattery


This code:

.text
.globl YYY

tells the assembler that you are going to write things in the "text" section, and that "YYY" is a global within that section. Your .type adds that "YYY" is the name of a function. That's not what you want: you want the section to be named "YYY", not the function itself. To select a section with a specific name, use a .section directive (.text is just a shortcut for a .section which designates the "text" section).

like image 24
Thomas Pornin Avatar answered Jun 30 '26 08:06

Thomas Pornin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!