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

relocation R_X86_64_PC32 against absolute symbol _binary_python_extension_py_size' in section .text' is disallowed #250

Closed
oxr463 opened this issue Apr 20, 2021 · 8 comments · Fixed by #285

Comments

@oxr463
Copy link
Collaborator

oxr463 commented Apr 20, 2021

Expected Behavior

Building a PRoot binary.

Actual Behavior

Python extension error when building.

Steps to Reproduce the Problem

make -C src loader.elf loader-m32.elf build.h
make -C src proot

Specifications

  • Proot/Care version: 8c0ccf7
  • Kernel version: Linux 49c896f37a82 5.11.0-7612-generic #13~1617215757~20.10~97a8d1a-Ubuntu SMP Thu Apr 1 21:09:17 UTC 2 x86_64 GNU/Linux
  • Host distribution: Pop!_OS v20.10
  • Guest distribution: Alpine v3.13.0

Command Output

make -C src proot
make: Entering directory '/usr/src/proot/src'
  LD	proot
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: extension/python/python.o: relocation R_X86_64_PC32 against absolute symbol `_binary_python_extension_py_size' in section `.text' is disallowed
collect2: error: ld returned 1 exit status
make: *** [GNUmakefile:179: proot] Error 1
make: Leaving directory '/usr/src/proot/src'
@oxr463
Copy link
Collaborator Author

oxr463 commented Apr 20, 2021

@oxr463

This comment has been minimized.

@oxr463
Copy link
Collaborator Author

oxr463 commented Jul 22, 2021

This might be specific to Alpine due to musl libc. I was able to build without any issues on Debian 10.

@chewi
Copy link
Contributor

chewi commented Aug 12, 2021

I've hit this on Gentoo with glibc. Perhaps it's GCC 11.2.

@oxr463
Copy link
Collaborator Author

oxr463 commented Aug 12, 2021

I've hit this on Gentoo with glibc. Perhaps it's GCC 11.2.

Ah... That's interesting. Let me see if I can reproduce on an older version.

@oxr463
Copy link
Collaborator Author

oxr463 commented Sep 2, 2021

cat /etc/os-release 
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.14.2
PRETTY_NAME="Alpine Linux v3.14"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://bugs.alpinelinux.org/"

gcc --version
gcc (Alpine 10.3.1_git20210424) 10.3.1 20210424
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

yuyichao added a commit to yuyichao/proot that referenced this issue Oct 1, 2021
It's difficult to use a *ABS* symbol from C code.
Specifying `-fPIC` could work around it but I'd like to not force it.
Instead, simply use the symbol pointing to the end of the file and
compute the size from the difference.

Fix proot-me#250
@oxr463 oxr463 self-assigned this Oct 1, 2021
oxr463 pushed a commit that referenced this issue Oct 1, 2021
* Fix python option handler...

... was this option ever used?

* Use the end symbol instead of the size symbol

It's difficult to use a *ABS* symbol from C code.
Specifying `-fPIC` could work around it but I'd like to not force it.
Instead, simply use the symbol pointing to the end of the file and
compute the size from the difference.

* Fix python3.8 linking

Starting python 3.8, the --ldflags by default omits the python library.
A new --embed option was added to restore the previous behavior.

Bug: #250
@oxr463
Copy link
Collaborator Author

oxr463 commented Oct 1, 2021

This has been fixed.

make -C src proot
make: Entering directory '/usr/src/proot/src'
  CC	cli/cli.o
  CC	cli/proot.o
  CC	cli/note.o
  CC	execve/enter.o
./execve/enter.c: In function 'extract_loader':
./execve/enter.c:529:2: warning: 'talloc_autofree_context' is deprecated [-Wdeprecated-declarations]
  529 |  loader_path = talloc_strdup(talloc_autofree_context(), path);
      |  ^~~~~~~~~~~
In file included from ./execve/enter.c:28:
/usr/include/talloc.h:1071:16: note: declared here
 1071 | _PUBLIC_ void *talloc_autofree_context(void) _DEPRECATED_;
      |                ^~~~~~~~~~~~~~~~~~~~~~~
  CC	execve/exit.o
  CC	execve/shebang.o
  CC	execve/elf.o
  CC	execve/ldso.o
  CC	execve/auxv.o
  CC	execve/aoxp.o
  CC	path/binding.o
  CC	path/glue.o
./path/glue.c: In function 'set_placeholder_destructor':
./path/glue.c:76:2: warning: 'talloc_autofree_context' is deprecated [-Wdeprecated-declarations]
   76 |  autofreed = talloc_autofree_context();
      |  ^~~~~~~~~
In file included from ./path/glue.c:31:
/usr/include/talloc.h:1071:16: note: declared here
 1071 | _PUBLIC_ void *talloc_autofree_context(void) _DEPRECATED_;
      |                ^~~~~~~~~~~~~~~~~~~~~~~
  CC	path/canon.o
In function 'next_component',
    inlined from 'canonicalize' at ./path/canon.c:229:14:
./path/canon.c:110:2: warning: 'strncpy' destination unchanged after copying no bytes [-Wstringop-truncation]
  110 |  strncpy(component, start, length);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  CC	path/path.o
  CC	path/proc.o
./path/proc.c: In function 'readlink_proc':
./path/proc.c:101:4: warning: 'strncpy' specified bound depends on the length of the source argument [-Wstringop-overflow=]
  101 |    strncpy(result, string, status + 1); \
      |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./path/proc.c:107:3: note: in expansion of macro 'SUBSTITUTE'
  107 |   SUBSTITUTE(exe, known_tracee->exe);
      |   ^~~~~~~~~~
./path/proc.c:97:13: note: length computed here
   97 |    status = strlen(string);  \
      |             ^~~~~~~~~~~~~~
./path/proc.c:107:3: note: in expansion of macro 'SUBSTITUTE'
  107 |   SUBSTITUTE(exe, known_tracee->exe);
      |   ^~~~~~~~~~
./path/proc.c:101:4: warning: 'strncpy' specified bound depends on the length of the source argument [-Wstringop-overflow=]
  101 |    strncpy(result, string, status + 1); \
      |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./path/proc.c:108:3: note: in expansion of macro 'SUBSTITUTE'
  108 |   SUBSTITUTE(cwd, known_tracee->fs->cwd);
      |   ^~~~~~~~~~
./path/proc.c:97:13: note: length computed here
   97 |    status = strlen(string);  \
      |             ^~~~~~~~~~~~~~
./path/proc.c:108:3: note: in expansion of macro 'SUBSTITUTE'
  108 |   SUBSTITUTE(cwd, known_tracee->fs->cwd);
      |   ^~~~~~~~~~
  CC	path/temp.o
./path/temp.c: In function 'get_temp_directory':
./path/temp.c:41:2: warning: 'talloc_autofree_context' is deprecated [-Wdeprecated-declarations]
   41 |  temp_directory = talloc_strdup(talloc_autofree_context(), tmp);
      |  ^~~~~~~~~~~~~~
In file included from ./path/temp.c:9:
/usr/include/talloc.h:1071:16: note: declared here
 1071 | _PUBLIC_ void *talloc_autofree_context(void) _DEPRECATED_;
      |                ^~~~~~~~~~~~~~~~~~~~~~~
./path/temp.c: In function 'create_temp_name':
./path/temp.c:287:3: warning: 'talloc_autofree_context' is deprecated [-Wdeprecated-declarations]
  287 |   context = talloc_autofree_context();
      |   ^~~~~~~
In file included from ./path/temp.c:9:
/usr/include/talloc.h:1071:16: note: declared here
 1071 | _PUBLIC_ void *talloc_autofree_context(void) _DEPRECATED_;
      |                ^~~~~~~~~~~~~~~~~~~~~~~
  CC	syscall/seccomp.o
  CC	syscall/syscall.o
  CC	syscall/chain.o
  CC	syscall/enter.o
  CC	syscall/exit.o
  CC	syscall/sysnum.o
  CC	syscall/socket.o
./syscall/socket.c: In function 'translate_socketcall_enter':
./syscall/socket.c:148:2: warning: 'strncpy' output may be truncated copying 108 bytes from a string of length 4095 [-Wstringop-truncation]
  148 |  strncpy(sockaddr.sun_path, host_path, sizeof_path);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  CC	syscall/heap.o
  CC	syscall/rlimit.o
In file included from ./syscall/rlimit.c:31:
./syscall/rlimit.c: In function 'translate_setrlimit_exit':
./cli/note.h:46:33: warning: format '%ld' expects argument of type 'long int', but argument 5 has type 'rlim_t' {aka 'long long unsigned int'} [-Wformat=]
   46 |    note(tracee, INFO, INTERNAL, (message), ## args); \
      |                                 ^~~~~~~~~
./syscall/rlimit.c:115:2: note: in expansion of macro 'VERBOSE'
  115 |  VERBOSE(tracee, 1, "stack soft limit increased to %ld bytes", proot_stack.rlim_cur);
      |  ^~~~~~~
  CC	tracee/tracee.o
  CC	tracee/mem.o
  CC	tracee/reg.o
  CC	tracee/event.o
  CC	ptrace/ptrace.o
  CC	ptrace/user.o
  CC	ptrace/wait.o
  CC	extension/extension.o
  CC	extension/kompat/kompat.o
  CC	extension/fake_id0/fake_id0.o
  CC	extension/link2symlink/link2symlink.o
./extension/link2symlink/link2symlink.c: In function 'decrement_link_count':
./extension/link2symlink/link2symlink.c:218:3: warning: 'strncpy' specified bound depends on the length of the source argument [-Wstringop-overflow=]
  218 |   strncpy(new_final, final, strlen(final) - 4);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./extension/link2symlink/link2symlink.c:218:29: note: length computed here
  218 |   strncpy(new_final, final, strlen(final) - 4);
      |                             ^~~~~~~~~~~~~
./extension/link2symlink/link2symlink.c: In function 'move_and_symlink_path':
./extension/link2symlink/link2symlink.c:139:3: warning: 'strncpy' specified bound depends on the length of the source argument [-Wstringop-overflow=]
  139 |   strncpy(new_final, final, strlen(final) - 4);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./extension/link2symlink/link2symlink.c:139:29: note: length computed here
  139 |   strncpy(new_final, final, strlen(final) - 4);
      |                             ^~~~~~~~~~~~~
  CC	extension/portmap/portmap.o
  CC	extension/portmap/map.o
  GEN	loader/loader-wrapped.o
  GEN	loader/loader-m32-wrapped.o
  CC	extension/python/python.o
  SWIG	proot_wrap.c
  CC	extension/python/proot_wrap.o
  GEN	extension/python/python_extension.o
  GEN	extension/python/proot.o
  LD	proot
rm python_extension.py
make: Leaving directory '/usr/src/proot/src'

@oxr463 oxr463 added this to the PRoot Next milestone Oct 1, 2021
dna2github pushed a commit to dna2fork/proot that referenced this issue May 1, 2023
* Fix python option handler...

... was this option ever used?

* Use the end symbol instead of the size symbol

It's difficult to use a *ABS* symbol from C code.
Specifying `-fPIC` could work around it but I'd like to not force it.
Instead, simply use the symbol pointing to the end of the file and
compute the size from the difference.

* Fix python3.8 linking

Starting python 3.8, the --ldflags by default omits the python library.
A new --embed option was added to restore the previous behavior.

Bug: proot-me#250
@OrangeDog
Copy link

The cause appears to have been https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94391

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

Successfully merging a pull request may close this issue.

3 participants