Some cleanups and tweaks for wc.1

2016-05-08 Thread Frederic Cambus
Hi tech@,

Some cleanups and tweaks for wc.1:

- Removed unnecessary string.h include
- Changed 'format_and_print' argument type to int64_t and casting
  inside the function
- Declaring 'print_counts', 'format_and_print', and 'cnt' as static
- Remove unnecessary cast for NULL, and (void) casts from printfs,
  'mbtowc' and 'format_and_print' calls
- In 'cnt', change bufsz type from ssize_t to size_t to avoid
  converting between pointers to integer types with different sign
  when calling getline (catched when compiling with Clang)
- Use return instead of exit in main

Index: wc.c
===
RCS file: /cvs/src/usr.bin/wc/wc.c,v
retrieving revision 1.20
diff -u -p -u -p -r1.20 wc.c
--- wc.c8 Dec 2015 01:00:45 -   1.20
+++ wc.c8 May 2016 21:51:28 -
@@ -34,7 +34,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -45,12 +44,12 @@
 
 int64_ttlinect, twordct, tcharct;
 intdoline, doword, dochar, humanchar, multibyte;
-intrval;
+intrval;
 extern char *__progname;
 
-void   print_counts(int64_t, int64_t, int64_t, char *);
-void   format_and_print(long long);
-void   cnt(char *);
+static void print_counts(int64_t, int64_t, int64_t, char *);
+static void format_and_print(int64_t);
+static void cnt(char *);
 
 int
 main(int argc, char *argv[])
@@ -82,10 +81,10 @@ main(int argc, char *argv[])
break;
case '?':
default:
-   (void)fprintf(stderr,
+   fprintf(stderr,
"usage: %s [-c | -m] [-hlw] [file ...]\n",
__progname);
-   exit(1);
+   return 1;
}
argv += optind;
argc -= optind;
@@ -99,7 +98,7 @@ main(int argc, char *argv[])
doline = doword = dochar = 1;
 
if (!*argv) {
-   cnt((char *)NULL);
+   cnt(NULL);
} else {
int dototal = (argc > 1);
 
@@ -111,14 +110,14 @@ main(int argc, char *argv[])
print_counts(tlinect, twordct, tcharct, "total");
}
 
-   exit(rval);
+   return rval;
 }
 
-void
+static void
 cnt(char *file)
 {
static char *buf;
-   static ssize_t bufsz;
+   static size_t bufsz;
 
FILE *stream;
char *C;
@@ -213,7 +212,7 @@ cnt(char *file)
++charct;
len = mbtowc(, C, MB_CUR_MAX);
if (len == -1) {
-   (void)mbtowc(NULL, NULL,
+   mbtowc(NULL, NULL,
MB_CUR_MAX);
len = 1;
wc = L' ';
@@ -263,31 +262,31 @@ cnt(char *file)
}
 }
 
-void 
-format_and_print(long long v)
+static void
+format_and_print(int64_t v)
 {
if (humanchar) {
char result[FMT_SCALED_STRSIZE];
 
-   (void)fmt_scaled(v, result);
-   (void)printf("%7s", result);
+   fmt_scaled((long long)v, result);
+   printf("%7s", result);
} else {
-   (void)printf(" %7lld", v);
+   printf(" %7lld", v);
}
 }
 
-void
+static void
 print_counts(int64_t lines, int64_t words, int64_t chars, char *name)
 {
if (doline)
-   format_and_print((long long)lines);
+   format_and_print(lines);
if (doword)
-   format_and_print((long long)words);
+   format_and_print(words);
if (dochar)
-   format_and_print((long long)chars);
+   format_and_print(chars);
 
if (name)
-   (void)printf(" %s\n", name);
+   printf(" %s\n", name);
else
-   (void)printf("\n");
+   printf("\n");
 }



Re: static in ze kernel

2016-05-08 Thread Stefan Fritsch
On Friday 29 April 2016 14:09:23, Mark Kettenis wrote:
> I think we should simply continue the current practice of not using
> static in the kernel.  I mean, what is the benefit of abandoning
> that practice if you disable the optimizations that compiler would
> make anyway?

You get a clear separation of public and non-public interfaces. You 
can throw away hundreds of useless prototypes for local functions. You 
are less likely to acumulate multiple prototypes for the same function 
which are later not kept in sync and cause subtle bugs.

Not using static in the kernel is bad.



vmctl: move some validations in start_vm()

2016-05-08 Thread Fabien Siron
Hi everyone,

The following patch moves all the validations of the start command in
start_vm() as suggested in the comment.

Index: main.c
===
RCS file: /cvs/src/usr.sbin/vmctl/main.c,v
retrieving revision 1.16
diff -u -p -r1.16 main.c
--- main.c  25 Apr 2016 15:14:34 -  1.16
+++ main.c  8 May 2016 19:23:20 -
@@ -188,20 +188,6 @@ vmmaction(struct parse_result *res)
 
switch (res->action) {
case CMD_START:
-   /* XXX validation should be done in start_vm() */
-   if (res->size < 1)
-   errx(1, "specified memory size too small");
-   if (res->path == NULL)
-   errx(1, "no kernel specified");
-   if (res->ndisks > VMM_MAX_DISKS_PER_VM)
-   errx(1, "too many disks");
-   else if (res->ndisks == 0)
-   warnx("starting without disks");
-   if (res->nifs == -1)
-   res->nifs = 0;
-   if (res->nifs == 0)
-   warnx("starting without network interfaces");
-
ret = start_vm(res->name, res->size, res->nifs,
res->ndisks, res->disks, res->path);
if (ret) {
Index: vmctl.c
===
RCS file: /cvs/src/usr.sbin/vmctl/vmctl.c,v
retrieving revision 1.13
diff -u -p -r1.13 vmctl.c
--- vmctl.c 13 Mar 2016 13:11:47 -  1.13
+++ vmctl.c 8 May 2016 19:23:21 -
@@ -67,6 +67,19 @@ start_vm(const char *name, int memsize, 
struct vm_create_params *vcp;
int i;
 
+   if (memsize < 1)
+   errx(1, "specified memory size too small");
+   if (kernel == NULL)
+   errx(1, "no kernel specified");
+   if (ndisks > VMM_MAX_DISKS_PER_VM)
+   errx(1, "too many disks");
+   else if (ndisks == 0)
+   warnx("stating without disks");
+   if (nnics == -1)
+   nnics = 0;
+   if (nnics == 0)
+   warnx("starting without network interfaces");
+
vcp = malloc(sizeof(struct vm_create_params));
if (vcp == NULL)
return (ENOMEM);

---
Regards,
Fabien Siron



Re: httpd: fix/style: unbalanced va_start and va_end macros

2016-05-08 Thread Joerg Jung
On Wed, Apr 27, 2016 at 02:43:27PM +0200, Hiltjo Posthuma wrote:
> Hi,
> 
> The following patch for httpd fixes unbalanced va_start() and va_end() macros.
> This is in style with the rest of httpd. Also POSIX says:
> 
> "Each invocation of the va_start() and va_copy() macros shall be matched by a
> corresponding invocation of the va_end() macro in the same function."
> 
> http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stdarg.h.html
> 

Yes agreed, the diff should be committed.
ok jung@ if a dev wants to take care
 
> Index: httpd.c
> ===
> RCS file: /cvs/src/usr.sbin/httpd/httpd.c,v
> retrieving revision 1.54
> diff -u -p -r1.54 httpd.c
> --- httpd.c   2 Feb 2016 17:51:11 -   1.54
> +++ httpd.c   27 Apr 2016 12:00:43 -
> @@ -1000,11 +1000,13 @@ kv_set(struct kv *kv, char *fmt, ...)
>   va_list   ap;
>   char*value = NULL;
>   struct kv   *ckv;
> + int ret;
>  
>   va_start(ap, fmt);
> - if (vasprintf(, fmt, ap) == -1)
> - return (-1);
> + ret = vasprintf(, fmt, ap);
>   va_end(ap);
> + if (ret == -1)
> + return (-1);
>  
>   /* Remove all children */
>   while ((ckv = TAILQ_FIRST(>kv_children)) != NULL) {
> @@ -1025,11 +1027,13 @@ kv_setkey(struct kv *kv, char *fmt, ...)
>  {
>   va_list  ap;
>   char*key = NULL;
> + int ret;
>  
>   va_start(ap, fmt);
> - if (vasprintf(, fmt, ap) == -1)
> - return (-1);
> + ret = vasprintf(, fmt, ap);
>   va_end(ap);
> + if (ret == -1)
> + return (-1);
>  
>   free(kv->kv_key);
>   kv->kv_key = key;
> 
> ---
> Kind regards,
> Hiltjo
> 



Re: httpd: patch for portability asprintf use

2016-05-08 Thread Joerg Jung
On Fri, May 06, 2016 at 06:48:38PM +0200, Reyk Floeter wrote:
> 
> > On 06.05.2016, at 18:36, Theo de Raadt  wrote:
> > 
> >> If OpenBSD's behavior of asprintf is non-standard and everyone else is
> >> doing it differently, we would probably have to apply the patch. But this
> >> would also affect many other places in the tree were we rely on our
> >> asprintf semantics.
> > 
> > Actually, we have fixed all usage cases in our tree to be portable.
> > 
> > I have wondered in the past whether we should set the pointer to (void
> > *)-1 instead of NULL, because this NULL return is a trap.
> > 
> 
> 
> I think enforcing it this way would make much sense.
> 
> I'm a candidate for such traps as I only develop C code on/for OpenBSD.
> 
> OK, this makes Hiltjo's diff a valid addition.

yes agreed, please commit it. ok jung@
 
> Reyk
> 



ftp/www.openbsd.org will be down for an upgrade today.

2016-05-08 Thread Bob Beck
There will be an extended downtime of the main ftp and www sites for
an upgrade today starting in approximately one hour's time from now.

The mirror sites should be unaffected - so use a mirror if you
discover the main site is unavailable today.

Thanks
-Bob



Re: More dbm(3) removal from man pages

2016-05-08 Thread Jason McIntyre
On Sun, May 08, 2016 at 05:42:33PM +0200, Christian Weisgerber wrote:
> jmc@ pointed out these places where dbm(3) is still mentioned.
> 
> For pwd_mkdb.8, I suggest to remove the whole paragraph.  It's been
> there since the very first version of the man page in the CSRG tree,
> 25 years ago.  At some point it was renamed from Compatibility to
> Standards, although it doesn't describe any standard.
> 
> ok?
> 

fine by me, and thanks (i wasn;t sure about a fix for the latter).
jmc

> Index: lib/libc/db/man/hash.3
> ===
> RCS file: /cvs/src/lib/libc/db/man/hash.3,v
> retrieving revision 1.19
> diff -u -p -r1.19 hash.3
> --- lib/libc/db/man/hash.310 Sep 2015 10:20:55 -  1.19
> +++ lib/libc/db/man/hash.38 May 2016 15:35:17 -
> @@ -130,8 +130,6 @@ will attempt to determine if the hash fu
>  the one with which the database was created, and will fail if it is not.
>  .Pp
>  Backward compatible interfaces to the routines described in
> -.Xr dbm 3
> -and
>  .Xr ndbm 3
>  are provided, although these interfaces are not compatible with
>  previous file formats.
> Index: usr.sbin/pwd_mkdb/pwd_mkdb.8
> ===
> RCS file: /cvs/src/usr.sbin/pwd_mkdb/pwd_mkdb.8,v
> retrieving revision 1.24
> diff -u -p -r1.24 pwd_mkdb.8
> --- usr.sbin/pwd_mkdb/pwd_mkdb.8  30 Nov 2015 17:03:05 -  1.24
> +++ usr.sbin/pwd_mkdb/pwd_mkdb.8  8 May 2016 15:35:17 -
> @@ -142,16 +142,6 @@ temporary file
>  .Xr getpwent 3 ,
>  .Xr passwd 5 ,
>  .Xr vipw 8
> -.Sh STANDARDS
> -Previous versions of the system had a program similar to
> -.Nm pwd_mkdb ,
> -.Sy mkpasswd ,
> -which built
> -.Xr dbm 3
> -style databases for the password file but depended on the calling programs
> -to install them.
> -The program was renamed in order that previous users of the program
> -not be surprised by the changes in functionality.
>  .Sh BUGS
>  Because of the necessity for atomic update of the password files,
>  .Nm
> -- 
> Christian "naddy" Weisgerber  na...@mips.inka.de



More dbm(3) removal from man pages

2016-05-08 Thread Christian Weisgerber
jmc@ pointed out these places where dbm(3) is still mentioned.

For pwd_mkdb.8, I suggest to remove the whole paragraph.  It's been
there since the very first version of the man page in the CSRG tree,
25 years ago.  At some point it was renamed from Compatibility to
Standards, although it doesn't describe any standard.

ok?

Index: lib/libc/db/man/hash.3
===
RCS file: /cvs/src/lib/libc/db/man/hash.3,v
retrieving revision 1.19
diff -u -p -r1.19 hash.3
--- lib/libc/db/man/hash.3  10 Sep 2015 10:20:55 -  1.19
+++ lib/libc/db/man/hash.3  8 May 2016 15:35:17 -
@@ -130,8 +130,6 @@ will attempt to determine if the hash fu
 the one with which the database was created, and will fail if it is not.
 .Pp
 Backward compatible interfaces to the routines described in
-.Xr dbm 3
-and
 .Xr ndbm 3
 are provided, although these interfaces are not compatible with
 previous file formats.
Index: usr.sbin/pwd_mkdb/pwd_mkdb.8
===
RCS file: /cvs/src/usr.sbin/pwd_mkdb/pwd_mkdb.8,v
retrieving revision 1.24
diff -u -p -r1.24 pwd_mkdb.8
--- usr.sbin/pwd_mkdb/pwd_mkdb.830 Nov 2015 17:03:05 -  1.24
+++ usr.sbin/pwd_mkdb/pwd_mkdb.88 May 2016 15:35:17 -
@@ -142,16 +142,6 @@ temporary file
 .Xr getpwent 3 ,
 .Xr passwd 5 ,
 .Xr vipw 8
-.Sh STANDARDS
-Previous versions of the system had a program similar to
-.Nm pwd_mkdb ,
-.Sy mkpasswd ,
-which built
-.Xr dbm 3
-style databases for the password file but depended on the calling programs
-to install them.
-The program was renamed in order that previous users of the program
-not be surprised by the changes in functionality.
 .Sh BUGS
 Because of the necessity for atomic update of the password files,
 .Nm
-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: libc/sparc64 ABI cleanup

2016-05-08 Thread Mark Kettenis
> Date: Sat, 7 May 2016 22:58:23 -0700
> From: Philip Guenther 
> 
> Currently, the soft-float bits in libc on sparc64 export not just the 
> sparc ABI symbols _Q_* and _Qp_*, but also the internal implementation 
> bits, __fpu_*
> 
> AFAICT, the __fpu_* names are not required by our tool chain; in contrast, 
> calls to the _Q* names are generated by gcc.
> 
> Diff below cleans this up, hiding the __fpu_* symbols, removing five 
> __fpu_* functions that are unused, and making sure that (almost) all the 
> internal references to _Q* go direct via hidden internal names.  This 
> reduces the PLT to just seven entries.
> 
> 
> Am I missing some secret requirement for __fpu_* to be exported?  
> Assuming not: oks?

No, I think these can be unexported.

I think the __fpu_explode() function could have been used to implement
"long double" versions of the standard C math functions at some point.
Perhaps we should remove that stuff completely instead of justdisabling
it.  But that can be a seperate polishing session.

ok kettenis@

> Index: arch/sparc64/Symbols.list
> ===
> RCS file: /cvs/src/lib/libc/arch/sparc64/Symbols.list,v
> retrieving revision 1.3
> diff -u -p -r1.3 Symbols.list
> --- arch/sparc64/Symbols.list 13 Sep 2015 08:31:47 -  1.3
> +++ arch/sparc64/Symbols.list 8 May 2016 05:51:42 -
> @@ -51,32 +51,6 @@ _Qp_uxtoq
>  _Qp_xtoq
>  __builtin_saveregs
>  __dtoul
> -__fpu_add
> -__fpu_compare
> -__fpu_div
> -__fpu_dtof
> -__fpu_explode
> -__fpu_ftod
> -__fpu_ftoi
> -__fpu_ftoq
> -__fpu_ftos
> -__fpu_ftox
> -__fpu_getreg32
> -__fpu_getreg64
> -__fpu_implode
> -__fpu_itof
> -__fpu_mul
> -__fpu_newnan
> -__fpu_norm
> -__fpu_qtof
> -__fpu_setreg32
> -__fpu_setreg64
> -__fpu_shr
> -__fpu_sqrt
> -__fpu_stof
> -__fpu_uitof
> -__fpu_uxtof
> -__fpu_xtof
>  __ftoul
>  __plt_end
>  __plt_start
> Index: arch/sparc64/fpu/Makefile.inc
> ===
> RCS file: /cvs/src/lib/libc/arch/sparc64/fpu/Makefile.inc,v
> retrieving revision 1.1
> diff -u -p -r1.1 Makefile.inc
> --- arch/sparc64/fpu/Makefile.inc 21 Jul 2003 18:41:30 -  1.1
> +++ arch/sparc64/fpu/Makefile.inc 8 May 2016 05:51:42 -
> @@ -1,4 +1,5 @@
>  #$OpenBSD: Makefile.inc,v 1.1 2003/07/21 18:41:30 jason Exp $
>  SRCS += fpu_add.c fpu_compare.c fpu_div.c fpu_explode.c fpu_implode.c \
> - fpu_mul.c fpu_qp.c fpu_q.c fpu_sqrt.c fpu_subr.c fpu_reg.c
> + fpu_mul.c fpu_qp.c fpu_q.c fpu_sqrt.c fpu_subr.c
> +# fpu_reg.c
>  .PATH: ${.CURDIR}/arch/sparc64/fpu
> Index: arch/sparc64/fpu/fpu_explode.c
> ===
> RCS file: /cvs/src/lib/libc/arch/sparc64/fpu/fpu_explode.c,v
> retrieving revision 1.7
> diff -u -p -r1.7 fpu_explode.c
> --- arch/sparc64/fpu/fpu_explode.c5 Dec 2012 23:19:59 -   1.7
> +++ arch/sparc64/fpu/fpu_explode.c8 May 2016 05:51:42 -
> @@ -292,6 +292,7 @@ __fpu_qtof(fp, i, j, k, l)
>   FP_TOF(exp, EXT_EXP_BIAS, frac, f0, f1, f2, f3);
>  }
>  
> +#if 0/* __fpu_explode is unused */
>  /*
>   * Explode the contents of a / regpair / regquad.
>   * If the input is a signalling NaN, an NV (invalid) exception
> @@ -362,3 +363,4 @@ __fpu_explode(fe, fp, type, reg)
>   DUMPFPN(FPE_REG, fp);
>   DPRINTF(FPE_REG, ("\n"));
>  }
> +#endif
> Index: arch/sparc64/fpu/fpu_extern.h
> ===
> RCS file: /cvs/src/lib/libc/arch/sparc64/fpu/fpu_extern.h,v
> retrieving revision 1.3
> diff -u -p -r1.3 fpu_extern.h
> --- arch/sparc64/fpu/fpu_extern.h 26 Jun 2008 05:42:05 -  1.3
> +++ arch/sparc64/fpu/fpu_extern.h 8 May 2016 05:51:42 -
> @@ -40,6 +40,7 @@ union instr;
>  struct fpemu;
>  struct fpn;
>  
> +__BEGIN_HIDDEN_DECLS
>  /* fpu.c */
>  int __fpu_exception(struct utrapframe *tf);
>  
> @@ -86,5 +87,6 @@ int __fpu_shr(register struct fpn *, reg
>  void __fpu_norm(register struct fpn *);
>  /* Build a new Quiet NaN (sign=0, frac=all 1's). */
>  struct fpn *__fpu_newnan(register struct fpemu *);
> +__END_HIDDEN_DECLS
>  
>  #endif /* !_SPARC64_FPU_FPU_EXTERN_H_ */
> Index: arch/sparc64/fpu/fpu_q.h
> ===
> RCS file: /cvs/src/lib/libc/arch/sparc64/fpu/fpu_q.h,v
> retrieving revision 1.2
> diff -u -p -r1.2 fpu_q.h
> --- arch/sparc64/fpu/fpu_q.h  3 Feb 2004 17:18:13 -   1.2
> +++ arch/sparc64/fpu/fpu_q.h  8 May 2016 05:51:42 -
> @@ -70,3 +70,23 @@ int _Qp_fgt(long double *, long double *
>  int _Qp_flt(long double *, long double *);
>  int _Qp_fne(long double *, long double *);
>  void _Qp_sqrt(long double *, long double *);
> +
> +PROTO_NORMAL(_Qp_add);
> +PROTO_NORMAL(_Qp_div);
> +PROTO_NORMAL(_Qp_dtoq);
> +PROTO_NORMAL(_Qp_feq);
> +PROTO_NORMAL(_Qp_fge);
> +PROTO_NORMAL(_Qp_fgt);
> +PROTO_NORMAL(_Qp_fle);
> +PROTO_NORMAL(_Qp_flt);
> 

Re: xclock patch

2016-05-08 Thread Theo de Raadt
> This patch forces xclock to read XErrorDB before pledge(). Further
> calls to any of the X error handler will used the in-memory copy (see
> libX11/src/ErrDes.c:147).

So basically, it primes the in-memory cache.  Then the syscall
codepaths are avoided later on. 

> I'm not yet 100% sure if there are other code path in lib X11/libXt
> that could cause an X application to read files on some events or not.

Indeed.  Other failing callpaths could be discovered in the future.

What I am seeing here is the correct "optimistic application" of
pledge to a program.  It is incremental learning.  Now we can look for
the next failure in this simple program.

(It would be nice if some folk performed a more academic study of
libX11; maybe there are places inside the library where it could
pre-cache automatically).

Eventually if the pledge strategy works in xclock, then it can apply
to other X programs.  This could result in the xterm pledge becoming
better.



Re: xclock patch

2016-05-08 Thread Matthieu Herrb
On Sat, May 07, 2016 at 02:01:34PM -0600, Theo de Raadt wrote:
> > > So I don't understand why pledge is being added here.
> > 
> > Because you suggested it back in november...
> 
> Of course I suggested it: I believe I said it would be nice if
> the simplest of X programs were investigated.
> 
> But everywhere else pledge was inserted, that requires (a) full
> understanding of what is being done, and (b) full testing.
> 
> It is not like I said "pledge xclock, noone gives a fuck if it
> works".
>  
> > > The addition of
> > > pledge is breaking xclock.  A pledge addition should not break a
> > > program (coredump) in any circumstance, it should only serve to secure
> > > it in conditions of true & undetected misbehaviour.  Sure, pledge can
> > > make programs safer, but only if they also keep working!!  Otherwise
> > > this is very much throwing the baby out with the bathwater.
> > 
> > I see only one solution here: remove the pledge until Xlib can be
> > changed to read XErrorDB early and then use the in-memory version for
> > error reporting.
> > 
> > ok?
> 

This patch forces xclock to read XErrorDB before pledge(). Further
calls to any of the X error handler will used the in-memory copy (see
libX11/src/ErrDes.c:147).

I'm not yet 100% sure if there are other code path in lib X11/libXt
that could cause an X application to read files on some events or not.

Index: xclock.c
===
RCS file: /cvs/OpenBSD/xenocara/app/xclock/xclock.c,v
retrieving revision 1.6
diff -u -p -u -r1.6 xclock.c
--- xclock.c11 Nov 2015 21:12:19 -  1.6
+++ xclock.c8 May 2016 10:37:48 -
@@ -228,6 +228,14 @@ main(int argc, char *argv[])
 #endif
 
 #ifdef HAVE_PLEDGE
+{
+/* force reading of XErrorDB into memory to avoid adding "rpath" to 
+   pledge below */
+int r;
+char buf[1];
+
+   r = XGetErrorDatabaseText(XtDisplay(toplevel), "XProtoError", "0", "",  
buf, 1);
+}
 if (pledge("stdio", NULL) == -1)
err(1, "pledge");
 #endif

-- 
Matthieu Herrb


signature.asc
Description: PGP signature


[patch] remove custom getline from vi

2016-05-08 Thread Martijn van Duren
Hello tech@,

I'm currently working on removing the binc family tree (including 
{GET,ADD}_SPACE_{RET,GOTO}) from vi. During this quest I found this gem 
which I reckon can be done better with the libc native function.

This has the benefit of extra checks from getline and it echos all 
system errors to the console instead of only malloc errors.

OK?

martijn@

Index: ex/ex_util.c
===
RCS file: /cvs/src/usr.bin/vi/ex/ex_util.c,v
retrieving revision 1.9
diff -u -p -r1.9 ex_util.c
--- ex/ex_util.c6 Jan 2016 22:28:52 -   1.9
+++ ex/ex_util.c8 May 2016 11:25:38 -
@@ -73,34 +73,26 @@ int
 ex_getline(SCR *sp, FILE *fp, size_t *lenp)
 {
EX_PRIVATE *exp;
-   size_t off;
-   int ch;
-   char *p;
+   ssize_t off;
+   long curr_off;
 
exp = EXP(sp);
-   for (errno = 0, off = 0, p = exp->ibp;;) {
-   if (off >= exp->ibp_len) {
-   BINC_RET(sp, exp->ibp, exp->ibp_len, off + 1);
-   p = exp->ibp + off;
+   curr_off = ftell(fp);
+   if ((off = getline(&(exp->ibp), &(exp->ibp_len), fp)) == -1) {
+   if (errno == EINTR) {
+   errno = 0;
+   clearerr(fp);
+   fseek(fp, curr_off, SEEK_SET);
+   return ex_getline(sp, fp, lenp);
}
-   if ((ch = getc(fp)) == EOF && !feof(fp)) {
-   if (errno == EINTR) {
-   errno = 0;
-   clearerr(fp);
-   continue;
-   }
-   return (1);
-   }
-   if (ch == EOF || ch == '\n') {
-   if (ch == EOF && !off)
-   return (1);
-   *lenp = off;
-   return (0);
-   }
-   *p++ = ch;
-   ++off;
+   if (errno)
+   msgq(sp, M_SYSERR, "getline");
+   return 1;
}
-   /* NOTREACHED */
+   if (exp->ibp[off-1] == '\n')
+   exp->ibp[--off] = '\0';
+   *lenp = off;
+   return 0;
 }
 
 /*



libc/sparc64 ABI cleanup

2016-05-08 Thread Philip Guenther

Currently, the soft-float bits in libc on sparc64 export not just the 
sparc ABI symbols _Q_* and _Qp_*, but also the internal implementation 
bits, __fpu_*

AFAICT, the __fpu_* names are not required by our tool chain; in contrast, 
calls to the _Q* names are generated by gcc.

Diff below cleans this up, hiding the __fpu_* symbols, removing five 
__fpu_* functions that are unused, and making sure that (almost) all the 
internal references to _Q* go direct via hidden internal names.  This 
reduces the PLT to just seven entries.


Am I missing some secret requirement for __fpu_* to be exported?  
Assuming not: oks?


Philip

Index: arch/sparc64/Symbols.list
===
RCS file: /cvs/src/lib/libc/arch/sparc64/Symbols.list,v
retrieving revision 1.3
diff -u -p -r1.3 Symbols.list
--- arch/sparc64/Symbols.list   13 Sep 2015 08:31:47 -  1.3
+++ arch/sparc64/Symbols.list   8 May 2016 05:51:42 -
@@ -51,32 +51,6 @@ _Qp_uxtoq
 _Qp_xtoq
 __builtin_saveregs
 __dtoul
-__fpu_add
-__fpu_compare
-__fpu_div
-__fpu_dtof
-__fpu_explode
-__fpu_ftod
-__fpu_ftoi
-__fpu_ftoq
-__fpu_ftos
-__fpu_ftox
-__fpu_getreg32
-__fpu_getreg64
-__fpu_implode
-__fpu_itof
-__fpu_mul
-__fpu_newnan
-__fpu_norm
-__fpu_qtof
-__fpu_setreg32
-__fpu_setreg64
-__fpu_shr
-__fpu_sqrt
-__fpu_stof
-__fpu_uitof
-__fpu_uxtof
-__fpu_xtof
 __ftoul
 __plt_end
 __plt_start
Index: arch/sparc64/fpu/Makefile.inc
===
RCS file: /cvs/src/lib/libc/arch/sparc64/fpu/Makefile.inc,v
retrieving revision 1.1
diff -u -p -r1.1 Makefile.inc
--- arch/sparc64/fpu/Makefile.inc   21 Jul 2003 18:41:30 -  1.1
+++ arch/sparc64/fpu/Makefile.inc   8 May 2016 05:51:42 -
@@ -1,4 +1,5 @@
 #  $OpenBSD: Makefile.inc,v 1.1 2003/07/21 18:41:30 jason Exp $
 SRCS += fpu_add.c fpu_compare.c fpu_div.c fpu_explode.c fpu_implode.c \
-   fpu_mul.c fpu_qp.c fpu_q.c fpu_sqrt.c fpu_subr.c fpu_reg.c
+   fpu_mul.c fpu_qp.c fpu_q.c fpu_sqrt.c fpu_subr.c
+# fpu_reg.c
 .PATH: ${.CURDIR}/arch/sparc64/fpu
Index: arch/sparc64/fpu/fpu_explode.c
===
RCS file: /cvs/src/lib/libc/arch/sparc64/fpu/fpu_explode.c,v
retrieving revision 1.7
diff -u -p -r1.7 fpu_explode.c
--- arch/sparc64/fpu/fpu_explode.c  5 Dec 2012 23:19:59 -   1.7
+++ arch/sparc64/fpu/fpu_explode.c  8 May 2016 05:51:42 -
@@ -292,6 +292,7 @@ __fpu_qtof(fp, i, j, k, l)
FP_TOF(exp, EXT_EXP_BIAS, frac, f0, f1, f2, f3);
 }
 
+#if 0  /* __fpu_explode is unused */
 /*
  * Explode the contents of a / regpair / regquad.
  * If the input is a signalling NaN, an NV (invalid) exception
@@ -362,3 +363,4 @@ __fpu_explode(fe, fp, type, reg)
DUMPFPN(FPE_REG, fp);
DPRINTF(FPE_REG, ("\n"));
 }
+#endif
Index: arch/sparc64/fpu/fpu_extern.h
===
RCS file: /cvs/src/lib/libc/arch/sparc64/fpu/fpu_extern.h,v
retrieving revision 1.3
diff -u -p -r1.3 fpu_extern.h
--- arch/sparc64/fpu/fpu_extern.h   26 Jun 2008 05:42:05 -  1.3
+++ arch/sparc64/fpu/fpu_extern.h   8 May 2016 05:51:42 -
@@ -40,6 +40,7 @@ union instr;
 struct fpemu;
 struct fpn;
 
+__BEGIN_HIDDEN_DECLS
 /* fpu.c */
 int __fpu_exception(struct utrapframe *tf);
 
@@ -86,5 +87,6 @@ int __fpu_shr(register struct fpn *, reg
 void __fpu_norm(register struct fpn *);
 /* Build a new Quiet NaN (sign=0, frac=all 1's). */
 struct fpn *__fpu_newnan(register struct fpemu *);
+__END_HIDDEN_DECLS
 
 #endif /* !_SPARC64_FPU_FPU_EXTERN_H_ */
Index: arch/sparc64/fpu/fpu_q.h
===
RCS file: /cvs/src/lib/libc/arch/sparc64/fpu/fpu_q.h,v
retrieving revision 1.2
diff -u -p -r1.2 fpu_q.h
--- arch/sparc64/fpu/fpu_q.h3 Feb 2004 17:18:13 -   1.2
+++ arch/sparc64/fpu/fpu_q.h8 May 2016 05:51:42 -
@@ -70,3 +70,23 @@ int _Qp_fgt(long double *, long double *
 int _Qp_flt(long double *, long double *);
 int _Qp_fne(long double *, long double *);
 void _Qp_sqrt(long double *, long double *);
+
+PROTO_NORMAL(_Qp_add);
+PROTO_NORMAL(_Qp_div);
+PROTO_NORMAL(_Qp_dtoq);
+PROTO_NORMAL(_Qp_feq);
+PROTO_NORMAL(_Qp_fge);
+PROTO_NORMAL(_Qp_fgt);
+PROTO_NORMAL(_Qp_fle);
+PROTO_NORMAL(_Qp_flt);
+PROTO_NORMAL(_Qp_fne);
+PROTO_NORMAL(_Qp_itoq);
+PROTO_NORMAL(_Qp_mul);
+PROTO_NORMAL(_Qp_qtod);
+PROTO_NORMAL(_Qp_qtoi);
+PROTO_NORMAL(_Qp_qtos);
+PROTO_NORMAL(_Qp_qtoui);
+PROTO_NORMAL(_Qp_sqrt);
+PROTO_NORMAL(_Qp_stoq);
+PROTO_NORMAL(_Qp_sub);
+PROTO_NORMAL(_Qp_uitoq);
Index: arch/sparc64/fpu/fpu_qp.c
===
RCS file: /cvs/src/lib/libc/arch/sparc64/fpu/fpu_qp.c,v
retrieving revision 1.5
diff -u -p -r1.5 fpu_qp.c
--- arch/sparc64/fpu/fpu_qp.c   17 Apr 2014 09:01:25 -  1.5
+++ arch/sparc64/fpu/fpu_qp.c   8 May 2016 05:51:42 -
@@ -37,7 +37,8 @@ __FBSDID("$FreeBSD: