This is an archive of the discontinued LLVM Phabricator instance.

Don't print DISCARD sections as gced
ClosedPublic

Authored by rafael on Feb 16 2017, 10:21 AM.

Details

Reviewers
ruiu
grimar
Summary

This is a small difference I noticed to gold and bfd. When given --print-gc-sections, we print sections a linkerscript marks DISCARD. The other linkers don't.

Diff Detail

Event Timeline

rafael created this revision.Feb 16 2017, 10:21 AM
grimar accepted this revision.Feb 17 2017, 1:56 AM

LGTM with a nit, looks reasonable behavior for me.

btw, currently (with or without this patch)
we do not report sections as discarded when linkerscript is used with -gc-sections at all (when there is no /DISCARD/):

# REQUIRES: x86
# RUN: echo "SECTIONS { }" > %t.script
# RUN: llvm-mc -triple x86_64-pc-linux %s -o %t.o -filetype=obj
# RUN: ld.lld -o %t -T %t.script %t.o --print-gc-sections --gc-sections 2>&1 | \
# RUN:   FileCheck -check-prefix=NOREPORT --allow-empty %s
# NOREPORT-NOT: removing unused section

.section .foo,"a"
.quad 0
test/ELF/linkerscript/discard-print-gc.s
4

Do you need -shared ? We link fine when do not have _start I think, if that was the case.

This revision is now accepted and ready to land.Feb 17 2017, 1:56 AM
ruiu added inline comments.Feb 21 2017, 10:19 AM
ELF/LinkerScript.cpp
279–280

Can this happen? It seems more like an ASSERT rather than an error().

ruiu accepted this revision.Feb 21 2017, 11:19 AM

LGTM

grimar closed this revision.Aug 17 2017, 2:27 AM

r295467