--
邮件自: 列表“openresty”,专用于技术讨论!
发言: 请发邮件到 open...@googlegroups.com
退订: 请发邮件至 openresty+...@googlegroups.com
详情: http://groups.google.com/group/openresty
官网: http://openresty.org/
仓库: https://github.com/agentzh/ngx_openresty
建议: 提问的智慧 http://wiki.woodpecker.org.cn/moin/AskForHelp
教程: http://agentzh.org/misc/nginx/agentzh-nginx-tutorials-zhcn.html
On Tue, Nov 13, 2012 at 4:20 AM, lhmwzy wrote:
> nginx/sbin/nginx的大小为10M,正常的NGINX大小只有几百K,是不是加的插件多了,就变大了?
>
可执行文件的大部分空间其实都是调试符号:
$ ls -lh /usr/local/openresty/nginx/sbin/nginx
-rwxr-xr-x. 1 root root 9.6M Nov 11 11:50
/usr/local/openresty/nginx/sbin/nginx*
$ sudo strip /usr/local/openresty/nginx/sbin/nginx
$ ls -lh /usr/local/openresty/nginx/sbin/nginx
-rwxr-xr-x. 1 root root 992K Nov 13 11:28
/usr/local/openresty/nginx/sbin/nginx*
我们看到,strip 掉可执行文件中的调试符号后,就从 9.6 MB 缩小到只有 992KB 了。但是,这样的话,使用 gdb 或者
systemtap/dtrace 就无法得到函数名、文件名以及行号等很多信息了。
如果你想保留调试符号,同时也真的很在乎可执行文件的大小的话,可以使用 DWARF 4 新增的 .debug_types
段特性来对调试符号进行压缩。具体做法是使用类似下面这样的命令行重新构造 openresty:
./configure --with-luajit --with-cc-opt='-fdebug-types-section' -j8
make -j8
sudo make install
然后我们再来看一下 nginx 可执行文件的大小:
$ ls -lh /usr/local/openresty/nginx/sbin/nginx
-rwxr-xr-x. 1 root root 3.8M Nov 13 11:32
/usr/local/openresty/nginx/sbin/nginx*
现在只有 3.8 MB 了,相比原先的 9.6 MB 缩小了 60% 以上。
Best regards,
-agentzh
2012/11/13 lhmwzy:
> 在FreeBSD下,无效
>
> + gcc version: 4.2.1 20070719 [FreeBSD]
FreeBSD 9.0 默认的 gcc 4.2.1 是 5 年多以前的老版本。如果查看
build/nginx-1.2.4/objs/autoconf.err 文件末尾的错误信息的话,可以看到类似下面这样的输出:
checking for --with-ld-opt="-Wl,-rpath,/usr/local/openresty/luajit/lib"
cc1: error: unrecognized command line option "-fdebug-types-section"
即这个老版本的 gcc 并不支持 -fdebug-types-section 选项。
如果你的 FreeBSD 系统已经安装有 gcc47 软件包的话,可以通过 --with-cc=gcc47 选项来使用 gcc 4.7 编译:
./configure --with-cc=gcc47 --with-luajit
--with-cc-opt='-fdebug-types-section' -j8
gmake -j8
gmake install
这样虽然可以成功构造,但出于某种我不知道的原因,DWARF4 的 debug types 段在 FreeBSD 上并没有生效:
$ readelf -WS /usr/local/openresty/nginx/sbin/nginx | fgrep .debug_types
该命令在 FreeBSD 9.0 上没有任何输出,所以可执行文件的大小还是 10MB.
而在 Linux 上,该命令是有输出的:
$ readelf -WS /usr/local/openresty/nginx/sbin/nginx | fgrep .debug_types
[34] .debug_types PROGBITS 0000000000000000
37ba4c 01ea00 00 0 0 1
即确实生效了。
或许你可以发邮件到 FreeBSD 的官方邮件列表问询 :)
Best regards,
-agentzh