I'm trying to add a new section to the dynamic library(libgfortran-2e0d59d6.so.5.0.0) using an objcopy tool, but looks like it breaks file alignment, which is checked by python during a library load. Probably it is true for many other libraries, but I've encountered only this one, yet.
Just running objcopy without any option also breaks it:
objcopy libgfortran-2e0d59d6.so.5.0.0
This results following:
Python 3.7.10 (default, Nov 16 2021, 10:44:16)
[GCC 9.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "./python3.7/site-packages/numpy/core/__init__.py", line 22, in <module>
from . import multiarray
File "./python3.7/site-packages/numpy/core/multiarray.py", line 12, in <module>
from . import overrides
File "./python3.7/site-packages/numpy/core/overrides.py", line 7, in <module>
from numpy.core._multiarray_umath import (
ImportError: libgfortran-2e0d59d6.so.5.0.0: ELF load command address/offset not properly aligned
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "./python3.7/site-packages/numpy/__init__.py", line 140, in <module>
from . import core
File "./python3.7/site-packages/numpy/core/__init__.py", line 48, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.7 from "./bin/python"
* The NumPy version is: "1.19.5"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: libgfortran-2e0d59d6.so.5.0.0: ELF load command address/offset not properly aligned
section header diff before and after objcopy command:
< 21 .gnu_debuglink 00000020 0000000000000000 0000000000000000 0021ec60 2**2
---
> 21 .gnu_debuglink 00000020 0000000000000000 0000000000000000 00209160 2**2
54c54
< 24 .dynstr 00008c60 000000000041f000 000000000041f000 00216000 2**3
---
> 24 .dynstr 00008c60 000000000041f000 000000000041f000 0021f000 2**3
I've found similar threads in the forums, but still no proper answer. Embedding binary into elf with objcopy may cause alignment issues?
Is there any workaround to prevent objcopy breaking already existing sections and just appending the new data, or is there a newer version of it which is fixed? Is there a way to disable alignment check on python and what problems could it cause?
BTW, Binutils version is 2.33.1.
I've tried with different versions of objcopy, still same result. Tried with -set-alignment-flag, still same.