Skip to content

Link errors when mixing code models #2097

@palmer-dabbelt

Description

@palmer-dabbelt

I'm not sure if this is actually new, but it's the first time I've seen it: https://lore.kernel.org/all/202506290255.KBVM83vZ-lkp@intel.com/

   ld.lld: error: Function Import: link error: linking module flags 'Code Model': IDs have conflicting values: 'i32 3' from vmlinux.a(init.o at 899876), and 'i32 1' from vmlinux.a(net-traces.o at 1014596)

IMO this shouldn't be a link error. There's a comment saying

// Linking object files with different code models is undefined behavior
// because the compiler would have to generate additional code (to span
// longer jumps) if a larger code model is used with a smaller one.
// Therefore we will treat attempts to mix code models as an error.

but I don't agree with that. The code model determines which relocations should be emitted, there's easily definable behavior if all those relocations can be resolved (just link it and it runs fine) and if any of those relocations can't be resolved (emit a truncation error). That's the same behavior regardless of mixing code models, I don't see any object-wide behavior related to which code model is used. So I don't see where the UB creeps in.

That said, as far as I can tell this has been there since 2018 and we're just starting to see the errors now. I'd also expect this to trip up all over the place, so not sure what I'm missing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    [ARCH] risc-vThis bug impacts ARCH=riscv[FEATURE] LTORelated to building the kernel with LLVM Link Time Optimization[PATCH] SubmittedA patch has been submitted for review

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions