MCPcopy Index your code
hub / github.com/jetify-com/devbox / patch

Method patch

internal/patchpkg/patch.go:121–149  ·  view source on GitHub ↗

patch applies glibc patches to a binary and writes the patched result to outPath. It does not modify the original binary in-place.

(ctx context.Context, path, outPath string)

Source from the content-addressed store, hash-verified

119// patch applies glibc patches to a binary and writes the patched result to
120// outPath. It does not modify the original binary in-place.
121func (p *libPatcher) patch(ctx context.Context, path, outPath string) error {
122 cmd := &patchelf{PrintInterpreter: true}
123 out, err := cmd.run(ctx, path)
124 if err != nil {
125 return err
126 }
127 oldInterp := string(out)
128
129 cmd = &patchelf{PrintRPATH: true}
130 out, err = cmd.run(ctx, path)
131 if err != nil {
132 return err
133 }
134 oldRpath := strings.Split(string(out), ":")
135
136 cmd = &patchelf{
137 SetInterpreter: p.ld,
138 SetRPATH: append(p.rpath, oldRpath...),
139 AddNeeded: p.needed,
140 Output: outPath,
141 }
142 slog.Debug("patching glibc on binary",
143 "path", path, "outPath", cmd.Output,
144 "old_interp", oldInterp, "new_interp", cmd.SetInterpreter,
145 "old_rpath", oldRpath, "new_rpath", cmd.SetRPATH,
146 )
147 _, err = cmd.run(ctx, path)
148 return err
149}
150
151// patchelf runs the patchelf command.
152type patchelf struct {

Callers 1

copyFileMethod · 0.80

Calls 1

runMethod · 0.95

Tested by

no test coverage detected