Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 30 Sep 2019 01:36:23 +0300
From:      Oleksandr Rybalko <ray@ddteam.net>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org,  svn-src-head@freebsd.org
Subject:   Re: svn commit: r352875 - head/contrib/elftoolchain/elfcopy
Message-ID:  <CAJ1Oi8HML4HjO9ALd_MGuQUWCiS_EcT%2BbqEtnS0MQ-V_3g=5RQ@mail.gmail.com>
In-Reply-To: <201909292234.x8TMY260090143@repo.freebsd.org>
References:  <201909292234.x8TMY260090143@repo.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Should be "Put sections into expected offset in binary format."
Sorry.

=D0=BF=D0=BD, 30 =D0=B2=D0=B5=D1=80. 2019 =D0=BE 01:34 Aleksandr Rybalko <r=
ay@freebsd.org> =D0=BF=D0=B8=D1=88=D0=B5:

> Author: ray
> Date: Sun Sep 29 22:34:01 2019
> New Revision: 352875
> URL: https://svnweb.freebsd.org/changeset/base/352875
>
> Log:
>   ections into expected offset in binary format.
>   Calculate binary file offset using address field, bacause software know
> only offset to known data, not where to load segment.
>   With that patch, kernel .data section can have any alignment/offset -
> kernel boor fine.
>
>   PR:           235391
>   Reviewed by:  markj
>   MFC after:    1 month
>   Differential Revision:        D21827
>
> Modified:
>   head/contrib/elftoolchain/elfcopy/binary.c
>
> Modified: head/contrib/elftoolchain/elfcopy/binary.c
>
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D
> --- head/contrib/elftoolchain/elfcopy/binary.c  Sun Sep 29 20:44:13 2019
>       (r352874)
> +++ head/contrib/elftoolchain/elfcopy/binary.c  Sun Sep 29 22:34:01 2019
>       (r352875)
> @@ -49,22 +49,23 @@ create_binary(int ifd, int ofd)
>         Elf *e;
>         Elf_Scn *scn;
>         Elf_Data *d;
> +       Elf64_Addr baseaddr;
>         GElf_Shdr sh;
> -       off_t base, off;
> +       off_t baseoff, off;
>         int elferr;
>
>         if ((e =3D elf_begin(ifd, ELF_C_READ, NULL)) =3D=3D NULL)
>                 errx(EXIT_FAILURE, "elf_begin() failed: %s",
>                     elf_errmsg(-1));
>
> -       base =3D 0;
> -       if (lseek(ofd, base, SEEK_SET) < 0)
> +       baseoff =3D 0;
> +       if (lseek(ofd, baseoff, SEEK_SET) < 0)
>                 err(EXIT_FAILURE, "lseek failed");
>
>         /*
>          * Find base offset in the first iteration.
>          */
> -       base =3D -1;
> +       baseoff =3D -1;
>         scn =3D NULL;
>         while ((scn =3D elf_nextscn(e, scn)) !=3D NULL) {
>                 if (gelf_getshdr(scn, &sh) =3D=3D NULL) {
> @@ -76,14 +77,16 @@ create_binary(int ifd, int ofd)
>                     sh.sh_type =3D=3D SHT_NOBITS ||
>                     sh.sh_size =3D=3D 0)
>                         continue;
> -               if (base =3D=3D -1 || (off_t) sh.sh_offset < base)
> -                       base =3D sh.sh_offset;
> +               if (baseoff =3D=3D -1 || (off_t) sh.sh_offset < baseoff) =
{
> +                       baseoff =3D sh.sh_offset;
> +                       baseaddr =3D sh.sh_addr;
> +               }
>         }
>         elferr =3D elf_errno();
>         if (elferr !=3D 0)
>                 warnx("elf_nextscn failed: %s", elf_errmsg(elferr));
>
> -       if (base =3D=3D -1)
> +       if (baseoff =3D=3D -1)
>                 return;
>
>         /*
> @@ -110,8 +113,8 @@ create_binary(int ifd, int ofd)
>                 if (d->d_buf =3D=3D NULL || d->d_size =3D=3D 0)
>                         continue;
>
> -               /* lseek to section offset relative to `base'. */
> -               off =3D sh.sh_offset - base;
> +               /* lseek to section offset relative to `baseaddr'. */
> +               off =3D sh.sh_addr - baseaddr;
>                 if (lseek(ofd, off, SEEK_SET) < 0)
>                         err(EXIT_FAILURE, "lseek failed");
>
>

--=20
WBW
-------
Rybalko Aleksandr <ray@ddteam.net>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAJ1Oi8HML4HjO9ALd_MGuQUWCiS_EcT%2BbqEtnS0MQ-V_3g=5RQ>