Skip to content

Different Relocation Handling for Function Pointers between LLVM and GCC in ARM32 #1441

Closed
@PuzzleZz

Description

@PuzzleZz

After switching to LLVM, we noticed different behavior in handling relocations, specifically for function pointer relocations. Here's a detailed example:

// Function definition and notifier block setup  
static int lkp_module_notifier(struct notifier_block *nb, unsigned long event, void *data)  
{  
    printk(KERN_ERR "this is lkp_module_notifier call\n");  
    return NOTIFY_OK;  
}  

static struct notifier_block lkp_nb = {  
    .notifier_call  = lkp_module_notifier,  
    .priority = 2,  
};  

LLVM's relocation handling for lkp_module_notifier:

Relocation section '.rel.data.lkp_nb' at offset 0x126c contains 1 entries:  
 Offset     Info    Type                Sym. Value  Symbol's Name  
00000000  00001802 R_ARM_ABS32            00000000   .text.lkp_module_notifier  

Corresponding section content:  
Hex dump of section '.data.lkp_nb':  
0x00000000 04000000 00000000 02000000          ............  

GCC's relocation handling for lkp_module_notifier:

Relocation section '.rel.data.lkp_nb' at offset 0x15b2c contains 1 entry:  
 Offset     Info    Type            Sym.Value  Sym. Name  
00000000  00000702 R_ARM_ABS32       00000004   lkp_module_notifier  

Corresponding section content:  
Hex dump of section '.data.lkp_nb':  
NOTE: This section has relocations against it, but these have NOT been applied to this dump.  
0x00000000 00000000 00000000 02000000          ............  

However, our kpatch tool processes relocations following the GCC format:

Relocation section '.rel.data.lkp_nb' at offset 0x52c contains 1 entries:  
 Offset     Info    Type                Sym. Value  Symbol's Name  
00000000  00000202 R_ARM_ABS32            00000004   lkp_module_notifier  

Corresponding section content:  
Hex dump of section '.data.lkp_nb':  
0x00000000 04000000 00000000 02000000          ............  

LLVM uses section symbol (.text.lkp_module_notifier) for relocation
GCC uses direct function symbol (lkp_module_notifier)
Our kpatch tool expects GCC-style relocations

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions