|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH v9 11/27] xsplice: Implement payload loading
> > +static int move_payload(struct payload *payload, struct xsplice_elf *elf)
> > +{
.. snip..
> > + /* Compute size of different regions. */
> > + for ( i = 1; i < elf->hdr->e_shnum; i++ )
> > + {
> > + if ( (elf->sec[i].sec->sh_flags & (SHF_ALLOC|SHF_EXECINSTR)) ==
> > + (SHF_ALLOC|SHF_EXECINSTR) )
> > + calc_section(&elf->sec[i], &payload->text_size, &offset[i]);
>
> This silently accepts writable text sections, yet the portion of the
> memory this gets placed in will be mapped RX.
I am not sure I follow. We only accept if sh_flags have AX. Not WAX?
How am I accepting writable text sections?
>
> > + else if ( (elf->sec[i].sec->sh_flags & SHF_ALLOC) &&
> > + !(elf->sec[i].sec->sh_flags & SHF_EXECINSTR) &&
> > + (elf->sec[i].sec->sh_flags & SHF_WRITE) )
> > + calc_section(&elf->sec[i], &payload->rw_size, &offset[i]);
> > + else if ( (elf->sec[i].sec->sh_flags & SHF_ALLOC) &&
> > + !(elf->sec[i].sec->sh_flags & SHF_EXECINSTR) &&
> > + !(elf->sec[i].sec->sh_flags & SHF_WRITE) )
> > + calc_section(&elf->sec[i], &payload->ro_size, &offset[i]);
> > + else if ( !elf->sec[i].sec->sh_flags ||
> > + (elf->sec[i].sec->sh_flags & SHF_EXECINSTR) ||
> > + (elf->sec[i].sec->sh_flags & SHF_MASKPROC) )
> > + /* Do nothing.*/;
> > + else if ( (elf->sec[i].sec->sh_flags & SHF_ALLOC) &&
> > + (elf->sec[i].sec->sh_type == SHT_NOBITS) )
> > + {
> > + dprintk(XENLOG_DEBUG, XSPLICE "%s: Not supporting %s
> > section!\n",
> > + elf->name, elf->sec[i].name);
> > + rc = -EOPNOTSUPP;
> > + goto out;
> > + }
>
> I saw this in the changelog, but I don't really understand these last
> two conditionals. Wouldn't you want to bail on _any_ sections which
The first (/Do nothing/) is for sections such as .rela.* (which we can
ditch after we are done), .symtab, .strtab (for which in later patches in
build_symbol_table construct a copy), and:
[ 1] .note.gnu.build-i NOTE 0000000000000000 00000040
0000000000000024 0000000000000000 A 0 0 4
which value we just copy in struct payload->id.
(also in later patch).
> have SHF_ALLOC set but don't get mapped to one of the three
> blocks? And wouldn't you (silently) ignore any sections with SHF_ALLOC
> clear?
Correct, such as:
[29] .shstrtab STRTAB 0000000000000000 000002fe
0000000000000143 0000000000000000 0 0 1
I've update the comments to be more clear.
..snip..
> > +int xsplice_elf_resolve_symbols(struct xsplice_elf *elf)
> > +{
> > + unsigned int i;
> > + int rc = 0;
> > +
> > + ASSERT(elf->sym);
> > +
> > + for ( i = 1; i < elf->nsym; i++ )
> > + {
> > + unsigned int idx = elf->sym[i].sym->st_shndx;
> > + Elf_Sym *sym = (Elf_Sym *)elf->sym[i].sym;
>
> Well, I admit that this is the more straightforward solution, but it
> opens up all of what sym points to for writing. I.e. I'd have
> considered it much better to really only do the casting away of
> const in the one spot where you need it (see below).
OK. That may become a bit cumbersome. We would have in the later
patches (xsplice,symbols: Implement symbol name resolution on addres)
the SHN_UNDEF doing symbol lookup. And that one tries to set
sym->st_value twice.
I can certainly cast it twice there, and then once in the default
case if you would like.
>
> > + switch ( idx )
> > + {
> > + case SHN_COMMON:
> > + dprintk(XENLOG_ERR, XSPLICE "%s: Unexpected common symbol:
> > %s\n",
> > + elf->name, elf->sym[i].name);
> > + rc = -EINVAL;
> > + break;
> > +
> > + case SHN_UNDEF:
> > + dprintk(XENLOG_ERR, XSPLICE "%s: Unknown symbol: %s\n",
> > + elf->name, elf->sym[i].name);
> > + rc = -ENOENT;
> > + break;
..snip..
> > + default:
..snip..
> > +
> > + sym->st_value += (unsigned long)elf->sec[idx].load_addr;
>
> *(<type> *)&sym->st_value += ...
Right, so I can cast it to a non-const and write to it. Keep in mind
that in this patch it is only one place, but in further I would have
to do this twice.
What is your preference?
>
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |