Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 25 Nov 2023 21:56:03 -0700
From:      Warner Losh <imp@bsdimp.com>
To:        Bakul Shah <bakul@iitbombay.org>
Cc:        Joseph Holsten <joseph@josephholsten.com>,  "freebsd-arm@freebsd.org" <freebsd-arm@freebsd.org>
Subject:   Re: sbrk
Message-ID:  <CANCZdfposZ2b0tDjwaQjqj1RVYKEK%2Bngr66wtkuRyUUq3r74Pw@mail.gmail.com>
In-Reply-To: <5668E8DE-B3B3-408D-978E-C2358A614803@iitbombay.org>
References:  <2F758BA2-F7F5-4A2C-85CF-6969EE50309C@iitbombay.org> <949f8f16-1219-4f4a-abf6-f9727c95681b@Spark> <CANCZdfqcA-kLd3gLWkcD1%2BPGFg48TPAF=OPk9HzRFyaokZbvAQ@mail.gmail.com> <5668E8DE-B3B3-408D-978E-C2358A614803@iitbombay.org>

next in thread | previous in thread | raw e-mail | index | archive | help
--0000000000003118ac060b070112
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Sat, Nov 25, 2023 at 8:58=E2=80=AFPM Bakul Shah <bakul@iitbombay.org> wr=
ote:

> On Nov 25, 2023, at 7:47=E2=80=AFPM, Warner Losh <imp@bsdimp.com> wrote:
>
>
> On Sat, Nov 25, 2023, 8:44 PM <joseph@josephholsten.com> wrote:
>
>> Yes, it=E2=80=99s no longer included. It=E2=80=99s long been deprecated,=
 but that does
>> make porting things like the original vi a bit challenging.
>>
>> Is there a particular project you=E2=80=99re trying to use it for?
>>
>
> It was never included in FreeBSD/arm64 due to the fact that the address
> space is complicated now and there no longer is an area beyond bss that y=
ou
> can expand into... let alone contract...
>
> Emacs was not happy with it...
>
>
> Thanks. Note that linux does provide it (may be not perfect but I thought
> FreeBSD cared more about compatibility....).
>
> This came up in trying to compile the v language
> https://github.com/vlang/v
>
> It uses a libgc which seems to be derived from some ancestor of BDW GC an=
d
> there are so many defines my eyes glaze over.
>

I see that it also uses tcc, which I coincidentally was looking at in the
cdefs modernization efforts I've been doing. You'll need at least one patch
to cdefs to get even the basics to compile. And three tests fail (one
doesn't matter, one is constructors and dtors and a third fails to detect
out of bounds access). I think only the ctor/dtor one is going to make
things hard for you. I've not looked into any of the test failures, just a
short-coming in cdefs.h since tcc doesn't support .symver yet.

sbrk can be faked with mmap of a large area up front with MAP_GUARD that's
then grown or shrunk as new sbrk calls happen and remapped with MAP_FIXED.
The only draw-back is you need reserve enough address space for all the
program's memory needs (like GB of space maybe). The MAP_GUARD mappings are
relatively cheap until it's actually used. Heck, you can even map SIGSEGV
to check to see if you've "overflowed" the area to make it bigger (I hate
that I know this trick, thank you Bourne shell).

Looks fun to play with. Maybe I'd help (but I already have too many fun and
even more un-fun projects).

Warner


> Warner
>
> --
>> Joseph Holsten
>> On Nov 25, 2023 at 19:41 -0800, Bakul Shah <bakul@iitbombay.org>, wrote:
>>
>> Does sbrk not exist on FreeBSD-14 on arm64? Is this by design?
>>
>> $ cat sb.c
>> #include <unistd.h>
>> #include <stdio.h>
>> int main(int c, char**v) {
>>         void *x =3D sbrk(102400);
>>         printf("%p\n", x);
>> }
>> $ cc sb.c
>> ld: error: undefined symbol: sbrk
>> >>> referenced by sb.c
>> >>>               /tmp/sb-e97caf.o:(main)
>> cc: error: linker command failed with exit code 1 (use -v to see
>> invocation)
>>
>>
>

--0000000000003118ac060b070112
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><br></div><br><div class=3D"gmail_quote">=
<div dir=3D"ltr" class=3D"gmail_attr">On Sat, Nov 25, 2023 at 8:58=E2=80=AF=
PM Bakul Shah &lt;<a href=3D"mailto:bakul@iitbombay.org">bakul@iitbombay.or=
g</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin=
:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"=
><div>On Nov 25, 2023, at 7:47=E2=80=AFPM, Warner Losh &lt;<a href=3D"mailt=
o:imp@bsdimp.com" target=3D"_blank">imp@bsdimp.com</a>&gt; wrote:<br><div><=
blockquote type=3D"cite"><div><div dir=3D"auto"><div><br><div class=3D"gmai=
l_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Sat, Nov 25, 2023, 8:44 P=
M  &lt;<a href=3D"mailto:joseph@josephholsten.com" target=3D"_blank">joseph=
@josephholsten.com</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote=
" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);=
padding-left:1ex">



<div>
<div name=3D"messageBodySection">
<div dir=3D"auto">Yes, it=E2=80=99s no longer included. It=E2=80=99s long b=
een deprecated, but that does make porting things like the original vi a bi=
t challenging.<br>
<br>
Is there a particular project you=E2=80=99re trying to use it for?</div></d=
iv></div></blockquote></div></div><div dir=3D"auto"><br></div><div dir=3D"a=
uto">It was never included in FreeBSD/arm64 due to the fact that the addres=
s space is complicated now and there no longer is an area beyond bss that y=
ou can expand into... let alone contract...</div><div dir=3D"auto"><br></di=
v><div dir=3D"auto">Emacs was not happy with it...</div></div></div></block=
quote><div><br></div>Thanks. Note that linux does provide it (may be not pe=
rfect but I thought FreeBSD cared more about compatibility....).=C2=A0</div=
><div><br></div><div>This came up in trying to compile the v language</div>=
<div><a href=3D"https://github.com/vlang/v" target=3D"_blank">https://githu=
b.com/vlang/v</a></div><div><br></div><div>It uses a libgc which seems to b=
e derived from some ancestor of BDW GC and there are so many defines my eye=
s glaze over.<br></div></div></blockquote><div><br></div><div>I see that it=
 also uses tcc, which I coincidentally was looking at in the cdefs moderniz=
ation efforts I&#39;ve been doing. You&#39;ll need at least one patch to cd=
efs to get even the basics to compile. And three tests fail (one doesn&#39;=
t matter, one is constructors and dtors and a third fails to detect out of =
bounds access). I think only the ctor/dtor one is going to make things hard=
 for you. I&#39;ve not looked into any of the test failures, just a short-c=
oming in cdefs.h since tcc doesn&#39;t support .symver yet.<br></div><div><=
br></div><div>sbrk can be faked with mmap of a large area up front with MAP=
_GUARD that&#39;s then grown or shrunk as new sbrk calls happen and remappe=
d with MAP_FIXED. The only draw-back is you need reserve enough address spa=
ce for all the program&#39;s memory needs (like GB of space maybe). The MAP=
_GUARD mappings are relatively cheap until it&#39;s actually used. Heck, yo=
u can even map SIGSEGV to check to see if you&#39;ve &quot;overflowed&quot;=
 the area to make it bigger (I hate that I know this trick, thank you Bourn=
e shell).<br></div><div><br></div><div>Looks fun to play with. Maybe I&#39;=
d help (but I already have too many fun and even more un-fun projects).<br>=
</div><div><br></div><div>Warner<br></div><div>=C2=A0</div><blockquote clas=
s=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid r=
gb(204,204,204);padding-left:1ex"><div><div><blockquote type=3D"cite"><div>=
<div dir=3D"auto"><div dir=3D"auto">Warner</div><div dir=3D"auto"><br></div=
><div dir=3D"auto"><div class=3D"gmail_quote"><blockquote class=3D"gmail_qu=
ote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,20=
4);padding-left:1ex"><div><div name=3D"messageSignatureSection">
--
<div dir=3D"auto">Joseph Holsten</div>
</div>
<div name=3D"messageReplySection">On Nov 25, 2023 at 19:41 -0800, Bakul Sha=
h &lt;<a href=3D"mailto:bakul@iitbombay.org" rel=3D"noreferrer" target=3D"_=
blank">bakul@iitbombay.org</a>&gt;, wrote:<br>
<blockquote type=3D"cite" style=3D"border-left:thin solid grey;margin:5px;p=
adding-left:10px">Does sbrk not exist on FreeBSD-14 on arm64? Is this by de=
sign?
<div><br></div>
<div><font face=3D"Menlo">$=C2=A0</font>cat sb.c</div>
<div>#include &lt;unistd.h&gt;</div>
<div>#include &lt;stdio.h&gt;</div>
<div>int main(int c, char**v) {</div>
<div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 void *x =3D sbrk(102400);</div>
<div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 printf(&quot;%p\n&quot;, x);</div>
<div>}</div>
<div>$ cc sb.c</div>
<div>ld: error: undefined symbol: sbrk</div>
<div>&gt;&gt;&gt; referenced by sb.c</div>
<div>&gt;&gt;&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 /tmp/sb-=
e97caf.o:(main)</div>
<div>cc: error: linker command failed with exit code 1 (use -v to see invoc=
ation)</div>
<div><br></div>
</blockquote>
</div>
</div>

</blockquote></div></div></div>
</div></blockquote></div><br></div></blockquote></div></div>

--0000000000003118ac060b070112--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CANCZdfposZ2b0tDjwaQjqj1RVYKEK%2Bngr66wtkuRyUUq3r74Pw>