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

replace strings in ELF .rodata sections #1344

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

ahgamut
Copy link
Collaborator

@ahgamut ahgamut commented Dec 27, 2024

With tool/build/renamestr (or an equivalent feature), I hope to avoid the /zip folder when building binaries with https://github.com/ahgamut/superconfigure. Most of the folder locations involving /zip are stored in the .rodata section of the ELF binary, and /zip is more useful for the APE than the debug ELF binaries.

The current build process on superconfigure involves:

  • create a /zip folder using sudo
  • any config data that a binary requires (terminfo entries, SSL certs) is copied to /zip
  • debug binaries use the actual /zip folder (or crash)

With this PR, the build process hopefully becomes:

  • no need to create a /zip folder with sudo
  • install config data to the usual location( $LOCATION/superconfigure/cosmos/$ARCH/$SUBFOLDER)
  • run renamestr on the ELF binary to replace $LOCATION/superconfigure/cosmos/$ARCH/ to /zip, before running apelink
  • now debug binaries will work like regular ELF binaries built on a Linux system

Perhaps this feature can be part of apelink itself (the structure and some code of renamestr is copied from apelink), but I wrote a separate tool in a draft PR, for an initial exploration.

@github-actions github-actions bot added the tool label Dec 27, 2024
@ahgamut
Copy link
Collaborator Author

ahgamut commented Dec 28, 2024

Have confirmed that renamestr avoids the use of /zip for building bash and berry in superconfigure:

image

(There is a build error relating to the installation of terminfo entries, but I assume that is due my system interfering with the ncurses build process).

@ahgamut ahgamut marked this pull request as ready for review December 28, 2024 10:29
ahgamut added a commit to ahgamut/superconfigure that referenced this pull request Jan 11, 2025
jart/cosmopolitan#1344

the renamestr program written in the above PR means the build process
for binaries in superconfigure does not require the existence of /zip
or equivalent folder as an absolute path to copy necessary assets. we
build the binaries setting $COSMOS as the target folder for all files
and then patch the .rodata section in the debug binaries right before
running apelink (actually, we run apelink with copies of the binaries
so that the originals can be used like regular ELF binaries installed
on a traditional Linux system.) Now, assuming binfmt_misc details are
satisfied, we should be able to build software without needing sudo.

/zip was needed in the build configuration of packages because it was
(at the time) the only way to ensure the final APE binary had correct
locations for reading assets. But /zip had several side effects: need
of sudo for creating the folder, COSMOPOLITAN_DISABLE_ZIPOS=1 for all
steps of superconfigure, debug binaries were difficult to use in case
we needed to fix a bug, some build flakes due to builds writing files
to the same subfolder of /zip, et cetera. Now, the build procedure of
superconfigure should (ideally) result in ELF binaries installed from
using cosmocc, and the /zip features are activated right when the fat
binary is created, which means finding errors is far more streamlined
tool/build/renamestr.c Show resolved Hide resolved
tool/build/renamestr.c Show resolved Hide resolved
tool/build/renamestr.c Outdated Show resolved Hide resolved
tool/build/renamestr.c Outdated Show resolved Hide resolved
tool/build/renamestr.c Outdated Show resolved Hide resolved
tool/build/renamestr.c Show resolved Hide resolved
tool/build/renamestr.c Outdated Show resolved Hide resolved
tool/build/renamestr.c Outdated Show resolved Hide resolved
tool/build/renamestr.c Show resolved Hide resolved
also use a string struct
if the string to replace is at the absolute end of the .rodata section,
it may not have a null terminating byte. In that case alone, we replace
one less byte than earlier, so as to avoid overwriting some other data.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants