Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected reloc type 0x00020001 on CentOS7 #120

Closed
nehaljwani opened this issue Oct 11, 2021 · 4 comments
Closed

Unexpected reloc type 0x00020001 on CentOS7 #120

nehaljwani opened this issue Oct 11, 2021 · 4 comments

Comments

@nehaljwani
Copy link
Contributor

Steps to reproduce:

$ sudo docker run -v /path/to/mold/install:/root/prefix --rm -it --net host centos:7 /bin/bash

# Install dependencies
$ yum install gcc-c++ python3-devel -y

# Source code for python3 module
$ cat <<EOF > Py_module.cc 
#include <Python.h>

static struct PyModuleDef moduledef = {
    PyModuleDef_HEAD_INIT, /* m_base */
    "pycore",              /* m_name */
    nullptr,               /* m_doc */
    -1,                    /* m_size */
    nullptr,               /* m_methods */
    nullptr,               /* m_slots */
    nullptr,               /* m_traverse */
    nullptr,               /* m_clear */
    nullptr                /* m_free */
};

PyMODINIT_FUNC PyInit_pycore(void)
{
    PyObject* module = PyModule_Create(&moduledef);
    if (module == nullptr)
    {
        return nullptr;
    }

    return module;
}
EOF

# Compile the object file
$ g++ -I/usr/include/python3.6m -fPIC -std=c++11 -o pycore.o -c Py_module.cc

# Generate shared library using mold
$ g++ -B$PWD/prefix/bin -shared -Wl,-soname,pycore.so -o pycore.so pycore.o
$ readelf -p .comment pycore.so 

String dump of section '.comment':
  [     0]  mold 0.9.6 (06c237838c9bde07820f0ad38c5421536dad4701; compatible with GNU ld and GNU gold)
  [    5b]  GCC: (GNU) 4.8.5 20150623 (Red Hat 4.8.5-44)

# Try to import it (fails!)
$ python3
Python 3.6.8 (default, Nov 16 2020, 16:55:22) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pycore
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: /pycore.so: undefined symbol: libstdc++.so.6

# Link and import it without mold (success!)
$ g++ -shared -Wl,-soname,pycore.so -o pycore.so pycore.o
$ python3
Python 3.6.8 (default, Nov 16 2020, 16:55:22) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pycore
>>> 

# Link again with mold, import with python2 just for fun (better error)
$ g++ -B$PWD/prefix/bin -shared -Wl,-soname,pycore.so -o pycore.so pycore.o
$ python
Python 2.7.5 (default, Nov 16 2020, 22:23:17) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pycore
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: ./pycore.so: unexpected reloc type 0x00020001
>>> 

# Version of ld.so
$ rpm -qf /lib64/ld-linux-x86-64.so.2 
glibc-2.17-324.el7_9.x86_64
@nehaljwani
Copy link
Contributor Author

Attaching statically linked mold (for use on glibc2.12+ , kernel 2.6.32+) for convenience: mold.gz

@rui314
Copy link
Owner

rui314 commented Oct 12, 2021

Thank you for your report! It looks dlopen() fails with any mold-generated shared object files on CentOS 7. Investigating...

@rui314 rui314 closed this as completed in ffb8e03 Oct 12, 2021
@rui314
Copy link
Owner

rui314 commented Oct 12, 2021

I believe the above change fixed the issue. Could you verify?

@nehaljwani
Copy link
Contributor Author

Verified. Thank you for the prompt fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants