mold icon indicating copy to clipboard operation
mold copied to clipboard

Mold fails to link due to error "string is not null terminated"

Open WTassoux opened this issue 2 years ago • 4 comments

Hello,

I have attempted to link our software using mold v2.1.0 for the first time. At link time, the following error happens:

mold: fatal: /composer_xe_2015.2.164/mkl/lib/intel64/libmkl_core.a(mkl_cpuid_patched.o):(.comment): string is not null terminated. The .comment section of this object contains the following entry (objdump -s -j .comment mkl_cpuid_patched.o):

mkl_cpuid_patched.o:     file format elf64-x86-64

Contents of section .comment:
 0000 2d646566 61756c74 6c69623a 6c696269  -defaultlib:libi
 0010 726320                               rc

It seems that mold is failing because it tries to find a null character before the end of the section, which is not present. The workaround I found is to take the size of the entire section if the null character was not found (elf/input-files.cc:721) by changing:

Fatal(ctx) << sec << ": string is not null terminated"; to: end = data.size() - entsize;

Regards,

William

WTassoux avatar Sep 06 '23 12:09 WTassoux

I think the terminating null character is mandatory by the ELF spec, and the compiler always adds it for you. Was your object file created by hand?

rui314 avatar Sep 06 '23 21:09 rui314

https://docs.oracle.com/cd/E23824_01/html/819-0690/ggdlu.html

If the section also has the SHF_STRINGS flag set, then the section can only contain null terminated strings. Null characters are only allowed as string terminators, and null characters must not appear within the middle of any string.

rui314 avatar Sep 07 '23 02:09 rui314

I think the terminating null character is mandatory by the ELF spec, and the compiler always adds it for you. Was your object file created by hand?

Up to my knowledge, no. MKL is a library part of Intel Parallel Studio and I don't think anyone in my company would have modified it manually, but I could be wrong. I will check with a fresh version of Parallel Studio if this library has the same issue.

WTassoux avatar Sep 07 '23 07:09 WTassoux

Yes, please. The timestamp in the filename implies that the library was built in 2015, which is 8 years ago, so Intel may have fixed it already.

rui314 avatar Sep 07 '23 10:09 rui314